I have been diving into C++ primer 5th edition these days. I found that on the page 452-453, it says shared_ptr automatically destroys its objects and frees the associated memory.
I don't quite understand it. So what's the difference between destroy the objects and free the associated memory?
Consider an object of this class:
class foo {
double* a;
foo() { a = new double();}
~foo() {delete a;}
}
If you want to clean up after using such an object, it is not sufficient to free the memory of that object, but you have to call the destrcutor so that also a gets deleted properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With