Hacker News new | past | comments | ask | show | jobs | submit login

Thanks for sharing, I’m unfamiliar with the nuances of Rust’s implementation of RAII as I’m primarily a modern C++ developer. Modern C++ mostly guarantees against leaks since it encourages the stack as much possible.

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppC...




It's the same deal as creating a circular references using `std::shared_ptr` in C++.


Ownership semantics in rust largely prevent circular references, so it's not the same deal


Sorry, I'm not a Rust pro, but from the docs about reference cycles linked above:

> We can see that Rust allows memory leaks by using Rc<T> and RefCell<T>: it’s possible to create references where items refer to each other in a cycle. This creates memory leaks because the reference count of each item in the cycle will never reach 0, and the values will never be dropped.

This sounds a lot like what happens when you create a circular reference with std::shared_ptr ?


Yes, but grep for `Rc::new()` in actual rust code bases compared to `shared_ptr` in C++. Interior mutability is cumbersome and not a natural pattern in practice.


Yes, it is the same thing.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: