[gclist] The requirments of finalizers and their consequences.

Charles Fiterman cef@geode.geodesic.com
Wed, 09 Oct 1996 08:13:57 +0100


Everyone seems to agree that finalizers need to be sure.
Everything constructed need to be finalized if only at
end of job.

They need to be ordered and users need control over that 
ordering. Further if an object contains two sub objects
with finalizers they can have different ordering. By ordering
I mean that a buffer object connected to a file object must
be able to say I must be finalized before the file object.
An object with two buffer objects must allow both to connect
to different files so the system must allow different ordering.

Finalizers must be general. This is a requirment of encapsulation.
If a finalizer object contains sub objects it must be able to
call on the services of those sub objects and not know how they
work. A rule against finalizers doing storage allocation defeats
encapsulation totally. It prevents finalizers from doing I/O for
example because I/O may do allocation.

There is some disagreement over the requirment of promptness. Users
accustomed to systems like Windows where resources are tight need
it and users accustomed to systems like Unix where they are abundant
find it unnessisary. But prompt finalizers are clearly superior 
because they need less resources.

I say the requirment of generality by itself forbids the collector
to do finalizers. If the collector invokes finalizers it must do
so at the end of the mark phase and before freeing objects. But a
general finalizer may do allocation and thus must be preceeded by
the free phase or part of it. But those objects may be required by
a finalizer and there is no way to tell which except to mark everything
a finalizer object points to. This may include other finalizer objects
and that kills the sure requirment. A chain of finalizer objects may
need an arbitrary number of collections to execute.

Further user controled ordering and composition defeat collector 
invoked finalization. A sub object finalizer may be invoked while
the super object lives.

This brings back the idea that finalizers must live on top of the
object system, using its services and not be invoked by the collector.

Charles Fiterman	Geodesic Systems
Phone 312-728-7196	4745 N. Ravenswood Suite 111
Fax   312-728-6096	Chicago Il 60015

A language without garbage collection is
like a city without garbage collection.