Resource acquisition is initialization (RAII) ties a resource’s lifetime to an object: acquire it during construction and release it during destruction. Scope then handles cleanup automatically, even when the object is stored inside a container. section 6.2.2
RAII appears in several common ownership patterns:
- A vector destroys its contained objects when it leaves scope, but raw pointers in the vector only destroy the pointer values, not their targets. section 6.2.2
- A unique_ptr owns one underlying pointer; copying is disabled, moving is allowed, and deletion occurs by default at destruction. section 6.2.2
- A shared_ptr permits multiple owners and destroys the object after the final owner is destroyed or reset. section 6.2.2
- A custom deleter lets RAII perform cleanup other than delete, such as destroying a coroutine handle. section 8.3.4
Smart pointers in a vector
void very_smart() { std::vector<SmartPointer<Blob>> blobs; blobs.emplace_back(make_smart_pointer<StepperBlob>()); } When blobs leaves scope, its element is destroyed, and the smart pointer performs its configured cleanup. section 6.2.2



