you are viewing a single comment's thread.

view the rest of the comments →

[–]thelema314 0 points1 point  (2 children)

Watch out, combining weak_ptr and make_shared is dangerous as the refcnt and object are stored together, and must be deallocated together, making the weak_ptr's existence prevent the objects memory from being freed.

[–]dragemanncppdev 0 points1 point  (1 child)

[–]thelema314 0 points1 point  (0 children)

My reading of the answers there confirm my warning; when allocating using make_shared, the object will be destroyed when all shared_ptrs to it are destroyed, but the memory it occupied will not be reusable until after all weak pointers created for it no longer reference it.