Jump to content

Resource acquisition is initialization

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Wlievens (talk | contribs) at 08:45, 31 May 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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.