[gclist] Destructor FAQ

boehm.PARC@xerox.com boehm.PARC@xerox.com
Wed, 13 Mar 1996 11:33:07 PST


"It seems to me that the finalization issue depends somewhat on whether
the language is an "everything in the heap" sort of language.  If not,
finalization order can be more well defined."

I would argue that we should distinguish between 2 concepts:

- destructors (a.k.a Ada "finalization")  These are basically actions invoked
at predefined times when a variable goes out of scope.  These can safely be
used for all sorts of things, including releasing locks, closing windows, etc.

- finalization (not Ada "finalization").  These are actions invoked
asynchronously when the system determines that an object (usually in the heap)
can no longer be accessed.  Useful only for non-time-critical resource
management and possibly emergency cleanup after exceptions.  Can be useful for
cleaning up file handles in a pinch, though this probably requires invoking the
garbage collector when you run out of file handles, just as it is likely to be
invoked if you run out of memory.  Not normally useful for releasing locks.

Sometimes the same syntax is used for both (e.g. in the Ellis-Detlefs proposal
for C++).  But it's important to remember they have different uses.  Given Ada
terminology, it may be that we need to do some renaming.  (I believe the other
use of "finalization" preceded Ada, however.)

Ordering issues probably matter for both, given the elaborate C++ hacks to get
destructor ordering for statically allocated objects right.

Hans