[gclist] Finalization and death notices
Mon, 8 Oct 2001 15:21:43 -0700
> -----Original Message-----
> Finalizers need to operate at end of job death notices do
> not. The reason
> is that death notices are independent objects owned by the user. The
> Collector simply moves them from one list to another. At end
> of job the
> user may examine unsent death notices. But a finalizer is object
> completion, an object may control some resource and the
> finalizer releases
> it. If end of job fails to invoke the finalizer we have a serious bug.
I strongly disagree. If you run a finalizer at process end eventhough the
corresponding object is still accessible, you have a serious bug, not the
other way around. The finalizer can see global data structures referenced
by a statically allocated pointer in an already finalized state. That means
you've just broken the only way of getting finalizer ordering in Java, among
more serious problems.
The garbage collector does not run finalizers for objects still accessible
at process exit. You can keep resources that need to be cleaned up at exit
in a separate list and explicitly deallocate them on exit. And that makes
sense, since in this case you are deallocating resources at a well-defined
program point, something for which finalizers are not suited.