C++ Language/Indirection/SmartPointers/SharedOwnership

Multiple std::shared_ptr<> variables can collectively manage a shared memory allocation, due to built-in reference-counting. C++ will automatically call delete on the underlying memory once all of the smart pointer variables have released their shared-ownership of it.

Additional information about shared_ptr (includes interactive examples)