RAII binds resource lifecycles (memory, sockets, mutexes) to object lifetimes. When an object goes out of scope on the stack, its destructor runs deterministically, freeing resources without manual cleanup.
cpp
#include <memory>
#include <mutex>
void process() {
std::lock_guard<std::mutex> lock(mtx); // Acquired
auto data = std::make_unique<Buffer>(); // Heap allocated
} // Mutex unlocked and buffer freed automatically