Help me understand your point of view. How does Rust not prevent memory leaks?
Comment on Which language you wish would really grow and reach mainstream adoption?
IAm_A_Complete_Idiot@sh.itjust.works 1 year agoRust doesn’t guarantee the lack of memory leaks anymore then java/C++ does, so sadly not sure if it would help here. :)
Rin@lemm.ee 1 year ago
IAm_A_Complete_Idiot@sh.itjust.works 1 year ago
There’s built in functions to leak memory that are perfectly safe. You can also do one really trivially by making a reference count cycle. doc.rust-lang.org/…/ch15-06-reference-cycles.html
Rust only prevents memory unsafety - and memory leaks are perfectly safe. It’s use after frees, double frees, etc. It prevents.
hairyballs@programming.dev 1 year ago
And here you’re only talking about a subset of memory leaks, by inaccessible memory. You can also leak memory by pushing new elements in a channel while never reading them for example.
zygo_histo_morpheus@programming.dev 1 year ago
You are absolutely correct that rusts safety features don’t extend to memory leaks, but it’s still better than most garbage collected languages unless you abuse Rc or something, and it does give you quite fine-grained controll over lifetimes, copying and allocations on the heap which in practice means that rust is fairly good about memory leakages compared to most languages.
IAm_A_Complete_Idiot@sh.itjust.works 1 year ago
How would rust fare any better then a tracing GC? Realistically I’d expect them to use more memory, and also have worse determinism in memory management - but I fail to really see a case where rust would prevent it and GC languages wouldn’t.
Akisamb@programming.dev 1 year ago
Reference counting is a GC though ?
It’s a bad one sure and will leak memory in cases of a cycle which most tracing GC are able to do.
It’s main advantage is that there are no GC pauses.
hairyballs@programming.dev 1 year ago
We can go further, I think it’s impossible to prevent memory leaks in a general purpose language
philm@programming.dev 1 year ago
Not without a super fancy type system that has to be still found. I think the key issue is cyclic data-structures (e.g. doubly-linked list). The language somehow needs to have strong/weak pointers and automatically determining them is a very complex research question…