Does the previous pointer automatically get destroyed (or dereferenced) in an std::shared_ptr if I assign a new one to it with the = operator?
For example:
std::shared_ptr< Type > sp1 (ptr1, std::ptr_fun(destroy));
std::shared_ptr< Type > sp2 (ptr2);
sp1 = sp2; // now, will ptr1 be dereferenced and / or destroyed?
// and will the destroy() function get called?
Yes, or else you would have a leak and it would defeat the purpose of having a smart ptr.
Just made a quick test and I didn’t get any leaks
Results:
. .