[gclist] Buffy finalizer slayer.
Fri, 11 Jun 1999 09:19:29 -0700
On Jun 11, 4:35pm, Nick Barnes wrote:
> As far as the semantics are concerned, it is absolutely unacceptable
> to have the collector say to the mutator "here's a dead object".
I think that's the wrong way to view it in any sort of precise semantics.
Finalizable objects are live, since they can still be accessed by the
finalizer. Finalization is run when an object is accessible only from
The Java language spec, for example, is fairly careful to define it this way.
In most models finalizable objects can subsequently again become reachable.
Thus they are clearly not dead.
> For instance, a program which uses finalization to ensure the
> availability of system resources (by cleaning up redundant resources)
> is not very reliable. Such a program will be especially unreliable
> with a generational conservative collector. Sooner or later the wrong
> integers will get on the stack at some point, and at some later point
> the program will die in an unreproducible way.
It depends on the resource. If the resource is memory, we have that problem
already. In several cases in which finalization is hard to avoid (building
block for distributed GC, calling explicit deallocation functions in libraries
not written for GC) the resource is actually memory. In other cases (e.g. file
descriptors) the resource may be virtualizable so as to make it about as
plentiful as memory.
Actually, my recommendation would be to use finalization to close file
descriptors only as a last resort, e.g. to recover from errors. Code to
explicitly handle those cases without finalization is likely to be so buggy
that it will be less reliable than any reasonable finalization implementation.