3 ms·
Ok, maybe, and definitely cool. But Java was supposed to prevent memory leaks but it's still possible :)
by exabrial 12y ago
Ok, maybe, and definitely cool. But Java was supposed to prevent memory leaks but it's still possible :)
- vitno 12y agoI 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.
- Ygg2 12y agoI think it's possible to leak even in safe code if you misuse RC/ARC and the family. EDIT: Box don't leak.
- kibwen 12y ago`Box` won't leak, but `Rc` is just simple reference counting and can leak if you don't use weak pointers to break cycles.
- mercurial 12y agoWhat'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.
- jsight 12y agoDepending 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.
- alephnil 12y agoThere 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.
- exabrial 12y agoThat comment was meant as a joke, hence why I used the smilee..... Sheesh HN
- mercurial 12y ago> 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.