3 ms·
Can anybody explain in simple terms how Rust can manage cycled memory, without a garbage collector?
by amelius 12y ago
Can anybody explain in simple terms how Rust can manage cycled memory, without a garbage collector?
- kzrdude 12y agoYou'll have to work hard to manage to create a cycle in the first place, regular ownership through a value or a Box<T> will not allow it. You can create cycles (that need to be broken manually) with the reference counted smart pointer Rc<T>, or you use its weak pointers to resolve it automatically. Oh, and datastructures that need cycles (the libstd's doubly linked list, for example), can use raw pointers to manage it manually, encapsulated in the implementation.