Skip to content
uencoder

Smart Pointer

Smart pointers use RAII to manage pointer lifetimes automatically, releasing when they leave scope and preventing leaks and dangling pointers.

Purpose

Automate memory management while balancing performance and safety — the core of modern C++/Rust.

Mechanism

C++ unique_ptr: exclusive ownership, move semantics. shared_ptr: reference-counted sharing. weak_ptr: weak reference without incrementing the count. Rust Box/Rc/Arc are similar. RAII: acquire in the constructor, release in the destructor.

Use cases

  • C++ memory management
  • Rust ownership
  • Resource safety

Related terms

References