[gclist] Finalizer counter-example

Marc Shapiro shapiro@prof.inria.fr
Thu, 4 Apr 1996 09:50:32 +0200


 || From: cef@geode.geodesic.com (Charles Fiterman)
 || To: gclist@iecc.com
 || Subject: [gclist] Put unnessisary code inside #if 0  #endif not finalizers.
 || Date: Wed, 3 Apr 1996 15:05:25 -0600
 || 
 || Please give me a real world example of code that belongs in a GC finalizer.

Distributed garbage collection is often cited as an example, but it is a poor
one.

Each process has its own local garbage collector.  A cross-process reference
is materialized by an outgoing stub and an ingoing scion.  One design for
distributed GC is to attach a finalizer to the stub; when the stub is freed,
its finalizer sends a delete message to delete the corresponding scion.

In fact the above design is flawed for a number of reasons (for instance the
delete message might get lost).  A better design is an array of weak pointers
to stubs.  A daemon periodically scans the array for stubs that have been
recently freed (identified by the fact that the GC has reset the weak pointer
to nil).

I suspect there are a number of examples involving finalizers that can equally
well be re-cast into a design based on weak pointers.

                                                Marc