[gclist] Put unnessisary code inside #if 0 #endif not finalizers.

Olivier Ridoux Olivier.Ridoux@irisa.fr
Thu, 4 Apr 1996 10:05:59 +0200



Dear Charles,

Your reasoning produces opposed conclusions based on similar hypotheses.  On
one hand you say that the basic assumption of GC is that not GCing is safe.
Anyhow, I presume you think GC is a useful feature.

> This may not be obvious but is is basic. Garbage collectors assume that
> not freeing somthing is safe. Conservative collection depends totally on
> that assumption. 

On the other hand when you say that finalizers must be such that it is safe not
to execute them, you conclude that it is better to have no finalizer.

> Finalizers break the assumption unless it is always safe not
> to execute the finalizer. If it is always safe not to execute the finalizer,
> why not have null finalization code?
> ...
> You have just said finalization should be reserved for unnessary code. Code
> that can be safely ignored.
> 
> So having finalization bound into gc is unnessary and expensive. You will need
> something else to free file handles etc. You will need something else for any
> work that really has to be done. GC finalizers will be reserved for that rare
> case where code is really unnessary. How often do you see that. Why complicate
> garbage collection for the convienience of unnessary code. I prefer #if 0
> for unnessary code myself. Delete it from the source when I am sure it is
> unnessisary. Putting it in finalizers seems to invite trouble, it might get
> executed.

>From your assumptions I would conclude instead that finalizers are useful just
for what GC is useful.  This leads me to answer you challenge.

> Please give me a real world example of code that belongs in a GC finalizer.

Assume that some objects in a GCed world are in fact boxes for pointers into
a non-GCed (but dynamically allocated) world (say malloc'ed stuff).  Assume
furthermore that the only accesses to the non-GCed world are from the GCed
world.  Then I see there a real world example of an application of a GC
finalizer.  This is in routine use in our LambdaProlog system for the management
of strings.  It can also be used for bignums, and in general for any largish
atomic objects that are better managed in their own world.

To conclude I see GC and finalizers are useful heuristics.  You can switch them
off but you will lose something.  How much will you lose?  This is the whole
subject of recurrent heated debates.  Note that MM in general is very difficult
to tune, and that its modelling is often subject to controversy.  This is also
a shared aspect with heuristics in general.

Olivier