Oddbean new post about | logout
 Smart pointers are extremely useful and make writing C++ a lot safer.

One of the most common bugs C has is leaking resources and double free-ing.

A smart pointer makes sure your resources are deallocated when they go out of scope. A shared smart pointer is one that when it gets copied, it points to the same resource but increases the ownership count, decreses the ownership count when it goes out of scope. So for shared smart pointers their resources only get release when  the ownership count drops to 0.