4 ms·
D is garbage-collected, but can be opted out of. Rust has no garbage collector.
by joobus 9y ago
D is garbage-collected, but can be opted out of. Rust has no garbage collector.
- yorwba 9y agoRust has an opt-in garbage collector as a library (https://docs.rs/gc/ https://docs.rs/gc/). I don't know how good it is, though.
- Rusky 9y agoBy that measure, so do C and C++.
- tcbawo 9y agoYou could implement GC in C++ using RAII (although smart pointers get you a long way). AFAIK, automatic GC is not possible with C.
- antientropic 9y agoIt absolutely is possible, via conservative GC: https://en.wikipedia.org/wiki/Boehm_garbage_collector https://en.wikipedia.org/wiki/Boehm_garbage_collector
- timlyo 9y agoWhat's the use case for a garbage collector in rust?
- yorwba 9y agoIf you have to share some data across your program and can't determine the lifetime at compilation time, you can't simply rely on the Rust compiler for memory management. The next option is to use reference counting by wrapping your data in Rc/Arc (depending on whether you need atomicity or not). But that can still leak memory if you have cyclic data structures and can't break the cycle with Weak pointers. At this point, what you need is a garbage collector.