Are there any downsides with using make_shared to create a shared_ptr

前端 未结 5 859
栀梦
栀梦 2020-12-12 20:33

Are there any downsides with using make_shared() instead of using shared_ptr(new T).

Boost documentation states

5条回答
  •  既然无缘
    2020-12-12 21:09

    In addition to the points presented by @deft_code, an even weaker one:

    • If you use weak_ptrs that live after all the shared_ptrs to a given object have died, then this object's memory will live in memory along with the control block until the last weak_ptr dies. In other words the object is destroyed but not deallocated until the last weak_ptr is destroyed.

提交回复
热议问题