Resource acquisition is initialization (RAII) is a programming idiom used
in several object-oriented, statically-typed programming languages to describe
a particular language behavior. In RAII, holding a resource is a class
invariant, and is tied to object lifetime. Resource allocation (or acquisition)
is done during object creation (specifically initialization), by the
constructor, while resource deallocation (release) is done during object
destruction (specifically finalization), by the destructor. In other words,
resource acquisition must succeed for initialization to succeed. Thus the
resource is guaranteed to be held between when initialization finishes and
finalization starts (holding the resources is a class invariant), and to be
held only when the object is alive. Thus if there are no object leaks, there
are no resource leaks.