▲ | AlotOfReading 5 days ago | |||||||||||||
C++'s design encourages that kind of allocation "leak" though. The article suggests using smart pointers, so let's take an example from there and mix make_shared with weak_ptr. Congrats, you've now extended the lifetime of the allocation to whatever the lifetime of your weak pointer is. Rc::Weak does the same thing in Rust, but I rarely see anyone use it. | ||||||||||||||
▲ | account42 4 days ago | parent | next [-] | |||||||||||||
std::weak_ptr is rarely used in C++ too - "I don't care if this thing goes away but still want to keep a reference to it" is just not good design in most cases. | ||||||||||||||
▲ | fluoridation 5 days ago | parent | prev [-] | |||||||||||||
Huh? What do you mean? The point of std::weak_ptr is that it's non-owning, so it has no effect on the lifetime of the pointed object. | ||||||||||||||
|