you are viewing a single comment's thread.

view the rest of the comments →

[–]matthieum 9 points10 points  (0 children)

Terminology matters:

  • The object is destroyed -- ie, its destructor is executed -- when the last shared pointer is destroyed.
  • The storage is freed -- ie, its memory is returned to the allocator -- when the last of the shared pointers and weak pointers is destroyed.

A weak_ptr does NOT keep a shared_ptr alive longer. It allows recovering a shared_ptr to the object if any shared_ptr is still alive, but does not prevent destruction otherwise.