There is a whole class of memory leaks that is possible in C but not in Java. You can leak memory by forgetting to deallocate it. This class is not possible in typical Java code, because the garbage collector collects it.
Then you have memory leaks that happens because the application has data structures that grow unbounded. The latter one is not really preventable by automatic means, because the memory is still referenced from elsewhere in the application, and a garbage collector can't know that this memory won't be accessed again.
It does help that the most common source of memory leaks is eliminated however. That many Java applications are memory hogs is more a result of typical Java programming style than anything else.
> It does help that the most common source of memory leaks is eliminated however. That many Java applications are memory hogs is more a result of typical Java programming style than anything else.
This may be part of it, but typically, the JVM will happily reclaim large chunks of memory from the OS, without necessarily allocating anything internally.
I mean, memory leaks are possible in Rust assuming the person explicitly uses unsafe code. However, most code does not use these unsafe blocks...
and it should not be possible. Rust has a sound type system that uses linear affine typing. While their implementation is not "proven correct", in practice if the Rust compiler is working properly, leaks will not happen.
What's keeping you from having a cache and forgetting to expunge it? It's fair to say that you have to work a lot harder in Rust to get a memory leak, while it requires no effort in C/C++, though.