DEV Community

Discussion on: How a weak_ptr might prevent full memory cleanup of managed object

Collapse
 
highperformancecoder profile image
Russell Standish

Wow - I didn't realise that make_shared can implement an intrusive shared pointer. I guess it doesn't have to, according to the standard, but it makes sense as an optimisation.

I usually use weak_ptrs to break cycles in object graphs - and this still works, because the weak_ptrs will be destroyed during the object destructor, meaning the memory deallocation will still happen, just not necessarily at the same time as the destructor is called.

What other uses do people use weak_ptrs for?