Resource Acquisition Is Initialization
Phrase · Development
Definitions
A C++ idiom (RAII) in which resource lifetime is tied to object scope: the constructor acquires the resource (memory, file handle, lock, socket) and the destructor releases it, guaranteeing cleanup even when exceptions are thrown. This eliminates manual resource management and is the foundation of smart pointers, lock guards, and file stream classes.
In plain English: A programming technique where resources like memory or file handles are automatically cleaned up when the code block that uses them finishes, preventing leaks.
Example: "With RAII, the mutex lock is released the instant the guard object goes out of scope — no try/finally needed, no chance of forgetting."