3 ms·
shared_ptr probably does use reference counting, but unique_ptr doesn't. There's literally only ever one "owner" of a unique_ptr, which is why the parent comme
by mpyne 14y ago
shared_ptr probably does use reference counting, but unique_ptr doesn't.
There's literally only ever one "owner" of a unique_ptr, which is why the parent comment talked about taking it from somewhere.
C++ exchanges ownership of unique_ptr's in the move constructor or assignment operator (i.e. there's no "copy" operation available, unlike with std::auto_ptr). If a unique_ptr still happens to own a pointer when the unique_ptr is destructed, it knows to destroy the pointed-to object as well and free the memory, but the object itself is not reference-counted per se, there's only the Boolean sense "alive/dead".