Resource Owners
oOwner: “something” that is responsible for the release of the resource
nScopes (global, local)—automatic destruction of stack objects and global/static objects
nObjects: recursively—automatic destruction of sub-objects
oBuilt-in ownership mechanisms
nDestruction at the end of the scope
nStack unwinding during exceptions
nRecursive destruction of sub-objects
o
A scope owns all its local variables (including function arguments within the scope of the function).
An object owns its member data, which may be objects themselves, recursively.
These two types of ownership guarantee resource release:
When a scope is exited, all local variables are destroyed. Stack unwinding make this process exception safe
When an object is destroyed, all its data members (and the base class part) is destroyed.
Note: We are assuming that no sane C++ programmer writes classes whose destructors may throw exceptions.