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

Charles Fiterman cef@geode.geodesic.com
Wed, 3 Apr 1996 15:05:25 -0600


 
> Am I the only one to think that "Garbage collection deletes objects when they
> can have no further effect on execution" is not obvious at all ?
> As I see it, GC cleans up objects when they are not reachable any more by
> the mutator. The default cleanup function being simply "free".

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. 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?

> I know that the R4RS defines the GC as a somewhat optional component which
> should not alter the behavior of the program (ignoring its memory-footprint),
> but I'm not sure whether this view was expressed for lack of interest in
> finalization-like tricks, for beauty's sake or really because that's
> what "GC was meant to be".
> 
> Sometimes you might prefer explicit destructors or any other "synchronous"
> cleanup system, but finalization, as I see it, is deeply bound into GC.

I agree finalization is deeply bound in to GC, to the detrement of both.

> Aside note: finalizers don't have to have visible effects on execution.
> For instance, finalizers which close files before freeing memory can probably
> be considered as "effect-free" (ignoring the filehandle-footprint).

Ignoring the file handle footprint will surely make you crash. Crashing is
not effect-free.

> It's probably good practice to avoid "loud" finalizers which have an important
> effect on the mutator, especially since you never know when (or if) a finalizer
> will be called. So you end up writing mostly "effect-free" finalizers.
> 
> If you need a finalizer that's "prompt and sure", you probably need something
> else since what is usually named "finalizer" is has no promptness guarantee.
> A finalizer should be merely an optional optimisation.

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.

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