18 ms·
I have never done anything with Rust but I was under the impression that Rust's borrowing and ownership system made manually freeing memory more or less obsolet
by foepys 10y ago
I have never done anything with Rust but I was under the impression that Rust's borrowing and ownership system made manually freeing memory more or less obsolete except for a few edge cases where the compiler isn't intelligent enough. Is this impression false?
- tatterdemalion 10y agoYou are correct, you essentially never need to manually free memory.
- adrianN 10y agoManual resource management in Rust is about as convenient as manual resource management in modern C++. That is, you don't really do any "manual" memory management at all in >90% of your code, it's all taken care of by RAII.
- pjmlp 10y agoYes, but with the added benefit not requiring external tooling to validate those RAII pattern are used correctly and forcing not so security savvy developers to actually use them.
- kazagistar 10y agoSo it's better, safer, but still manual memory management.
- pjmlp 10y agoNot quite, because the rules are enforced by the compiler. In C++ the rules are enforced by optional tooling that most developers don't use. At CppCon 2015, only 1% of the audience acknowledged using such tools at Herb's talk about the core guidelines.
- Manishearth 10y agoIt's still automatic. You don't need to call free. The only difference is that you need to deal with whether or not things go on the heap, are refcounted, etc (but this decision is in the types, so you make it once and are done). Whether or not that's "manual" depends on your point of view. I consider it to be more along the lines of choosing guarantees.
- Sean1708 10y agoI don't think Rust even allows you to free your own memory without calling into libc, but then again I suppose you could say the same thing about C.
- steveklabnik 10y agoNot on stable. On unstable you'd have a few options, similar to the ones you'd have for writing libc in the first place.
- moosingin3space 10y agoCan't you use mem::drop to (effectively) deallocate memory before it goes out of scope? (I know this isn't quite the same thing as liballoc on nightly)
- steveklabnik 10y agoThat's true. Even though my parent said "free", I just assumed both sides of the equation :)