Resource acquisition is initialization
Appearance
Resource Acquisition Is Initialization (RAII) is a technique in object oriented programming.
The technique states that, like the name implies, objects should initialise and release all resources they acquire.
It is of paramount importance especially in languages that do not support built-in garbage collection, such as C++.
A stereotypical example of RAII is the Standard Template Library's file-stream class. An input file stream is opened in the object's constructor, and it is closed upon destruction of the object. Since C++ allows objects to be allocated on the stack, C++'s scoping mechanism can be used to control file access.