3 ms·
Can you use lifetimes for most objects, and use GC where it's "hard"? Like, canonical example with double linked lists.
by KptMarchewa 5y ago
Can you use lifetimes for most objects, and use GC where it's "hard"? Like, canonical example with double linked lists.
- rtoway 5y agoYou can do this in Rust today, with the standard library's reference counter
- klodolph 5y agoAlso, one of the easiest ways to leak memory in Rust. My understanding is that substructural typing systems are just not quite powerful enough to represent the semantics of double-linked lists, but I don't understand the math myself. Obviously it won't leak memory if you do it correctly, but Rust will happily let you leak memory in an Rc<T>.
- ThomasWinwood 5y agoIf you really do want to leak memory, Rc<T> is overcomplicated - just call `Box::leak` and throw away the output.
- klodolph 5y agoRc<T> is the preferred way to introduce unintentional memory leaks.