C++workingcpp17

Smart pointers

RAII-owned heap memory that frees itself — no manual delete, no leaks.

std::unique_ptr and std::shared_ptr tie a heap allocation to a scope, so the destructor reclaims it automatically and ownership is explicit in the type.

unique_ptr owns and frees

C++intro
0ms
build 7using 7free 7after scope
Reference · output compiled offline, not runnable in-browser

free 7 prints before after scope, proving the Widget destructor fired the moment w left the inner block — RAII reclaims the heap allocation deterministically, with no manual delete.