Will the smart pointer or scoped pointers delete an object when the class has no destructor
If not, why not just leave the scope and let the object be deleted by itself?
Will the smart pointer or scoped pointers delete an object when the class has
Share
All class members are deleted even if you don’t have a destructor when the instance is deleted. Memory leaks occur when you deal with pointers:
In this case,
bitself will be destroyed when the instance ofAis deleted, but the memory it points to will not.In the case of smart pointers, which usually have some reference counting and memory cleanup in the destructor, the memory it points to will be explicitly destroyed by its destructor, and the destructor of the smart pointer will be implicitly called when the instance of the containing class is destroyed.