Since the counter and the object have the same distribution, they also use the same release.
The counter should be kept until the last shared_ptr and weak_ptr . If you have a large object (or many small objects) with long weak_ptr s, this can lead to a memory conflict if you make_shared shared_ptr via make_shared .
Secondly, if you have a third-party API that passes you a pointer or a resource descriptor and possibly has its own functionality, make_shared not suitable and cannot be used in each case. Creating your own make_ functions can cause messy details to help you deal with this problem, and also deal with the issue of exception.
Finally, while generic pointers are awesome, they are also too strong. Quite often, I want unique_ptr or even boost::scoped_ptr , or an intrusive reference count pointer, or the like, to represent ownership. shared_ptr should be used only when the situation actually involves joint ownership of the resource: using it willy-nilly, because it is "easy", as a rule, ends with the resource equivalent of spaghetti code.
Yakk
source share