3 ms·
Are you suggesting that memory leaks don't happen in Rust? Not only has that proven not to be true but the language for some reason seems to define memory leaks
by rc00 2y ago
Are you suggesting that memory leaks don't happen in Rust? Not only has that proven not to be true but the language for some reason seems to define memory leaks as safe behavior.
> based on my experience with Rust
This suggests that you haven't encountered references cycles at your level of experience:
https://doc.rust-lang.org/book/ch15-06-reference-cycles.html#reference-cycles-can-leak-memory https://doc.rust-lang.org/book/ch15-06-reference-cycles.html...
- whytevuhuni 2y ago> Are you suggesting that memory leaks don't happen in Rust? Their wording was "would be unlikely", rather than "don't happen". The affine(ish) type system, along with lifetimes, makes it so most objects have a single owner, and that owner always knows it is safe to deallocate. > for some reason seems to define memory leaks as safe behavior The reason is that Rust aims to prevent undefined behavior, and that is the only thing it defines as unsafe behavior. Memory leaks cannot cause a program to, for example, start serving credit cards or personal information to an attacker. Their behavior is well defined (maybe over-complicated thanks to Linux's overcommit, but still well defined). Rust does not protect against DoS attacks in any way. In fact it seems to enjoy DoSing itself quite a lot given how many things panic in the standard library.
- timschmidt 2y agowhytevuhuni has done a wonderful job of saying the things I meant, clearer than I am able to articulate them. But I just wanted to point out that this is the first sentence of the documentation you linked: "Rust’s memory safety guarantees make it difficult, but not impossible, to accidentally create memory that is never cleaned up (known as a memory leak)." My sentiment exactly. Rust makes it difficult to accidentally create memory leaks. If you try hard to do it, it's definitely possible. But it's tremendously more difficult to accomplish than in C/C++ where it accidentally happens all the time.