Last Updated: June 6, 2026
RAII is the C++ idiom that ties the lifetime of a resource (memory, an open file, a held mutex, a network socket, a GPU handle) to the lifetime of an object. A constructor acquires the resource; the destructor releases it. When the object goes out of scope, the cleanup happens on its own, no matter how the scope exits. This chapter introduces the idiom: what it means, why it matters, what a hand-written RAII wrapper looks like, and when one is required.