Shared Pointers

Next, we have the shared pointer. It follows the principle of keeping a reference count to maintain the count of its copies. The lesson below elaborates further.

We'll cover the following...

std::shared_ptr shares the ownership of the resource. They have two handles. One for the resource and one for the reference counter. By copying a std::shared_ptr, the reference count is increased by one. It is decreased by one if the std::shared_ptr goes out of scope. If the reference counter becomes the value 0 and therefore there is no std::shared_ptr referencing the resource, the C++ runtime automatically releases the resource. The release of the resource takes place at exactly the ...