The cleanup stack allows local pointer variables that are pushed
to the stack to be cleaned up automatically in case a function leaves. You
should generally prefer to leave instead of using the TRAP harness. TRAP harnesses
are expensive because they are slow and add complexity and code size. Note
that if you need to add an extra TRAP inside a leaving
function, you need to take a look at your error design.
A CBase-derived class's virtual destructor
is automatically invoked during cleanup, which is not the case for other classes.
For other classes you can provide explicit cleanup support via the TCleanupItem class.
Never push member data on the cleanup stack, as this will result in a double-deletion memory leak.
Pop( reference ) should always be used in favor
of Pop() or Pop( integer ). This
will expose pop sequence error bugs early, through a crash, instead of some
strange behavior that might be more difficult to debug.