Hacker News new | past | comments | ask | show | jobs | submit login

Ok, maybe, and definitely cool. But Java was supposed to prevent memory leaks but it's still possible :)



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.


That comment was meant as a joke, hence why I used the smilee..... Sheesh HN


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.


I think it's possible to leak even in safe code if you misuse RC/ARC and the family.

EDIT: Box don't leak.


`Box` won't leak, but `Rc` is just simple reference counting and can leak if you don't use weak pointers to break cycles.


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.


Depending upon your definition of "memory leak" it may be impossible to prevent them at the language level. Java's claim was much narrower than that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: