Smart Pointer
Noun · Development
Definitions
An object that behaves like a pointer but also owns the memory it points to, releasing it automatically when that ownership ends. Smart pointers apply the RAII idiom, resource acquisition is initialisation, to heap memory, removing most manual delete calls and the leaks, double frees, and dangling pointers that come with them. In C++, std::unique_ptr expresses sole ownership and can be moved but not copied; std::shared_ptr keeps a reference count in a control block and frees the object when the last owner goes away; and std::weak_ptr observes a shared object without keeping it alive, which is how reference cycles are broken. The older std::auto_ptr, with confusing copy semantics, was deprecated in C++11 and removed in C++17. Rust builds the same ideas into its standard library: Box for single ownership, Rc for single-threaded reference counting, and Arc for thread-safe counting, often combined with RefCell or Mutex for interior mutability.
In plain English: A wrapper around a memory address that automatically cleans up the memory when nobody needs it anymore, preventing leaks.
Example: "Use std::unique_ptr instead of raw new/delete and you will never have a double-free again."