paint-brush
Smart Pointer, shared_ptr, Automatic Pointer and unique_ptrby@holmeshe
774 reads
774 reads

Smart Pointer, shared_ptr, Automatic Pointer and unique_ptr

by Holmes He8mOctober 6th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Objects life-cycle is crucial. A mistake in determining an object’s lifecycle can lead to resource (e.g., memory, fd) leaks as the resource owned cannot be properly released and recycled for <a href="https://hackernoon.com/tagged/future" target="_blank">future</a> use. When the leak accumulates to a certain level, it crashes the whole system.<br>Objects life-cycle is also complicated since the ownership of one object might be relinquished by, transferred to, or shared with different entities which include but are not limited to variables, <a href="https://hackernoon.com/tagged/function" target="_blank">function</a> arguments, modules, data structures, containers, and threads. Again, the resource has to be released and recycled by one of the owners at some undetermined point.<br>There is no de-facto standard to determine objects life-cycle. Utilities like <strong>GC</strong> (garbage collection) that is used in Java, <strong>ARC</strong> used in Objective-C and all those pointers (ptrs) in C++, all have their pros and cons. However, this article is not about pros and cons but is focused on C++ resource management helper classes, Smart Pointer, <code class="markup--code markup--p-code">shared_ptr</code>, <code class="markup--code markup--p-code">auto_ptr</code> and <code class="markup--code markup--p-code">unique_ptr</code>.

Coin Mentioned

Mention Thumbnail
featured image - Smart Pointer, shared_ptr, Automatic Pointer and unique_ptr
Holmes He HackerNoon profile picture
Holmes He

Holmes He

@holmeshe

L O A D I N G
. . . comments & more!

About Author

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite