[Gc] Re: Do finalizers run at exit?

Achilleas Margaritis axilmar at otenet.gr
Tue Dec 25 15:13:15 PST 2007


Yes, there is a ton of documentation, but it is hard to locate it. 
Anyway, I have found the relevant page and read it, and it says what you 
say: that running finalizers at program exit is the wrong thing to do.

It's not difficult to register objects cleaning up things at the end of 
the program, but I think it should be optional: the client should have 
the ability to run all finalizers at exit, if he/she wishes to do so.

O/H Bruce Hoult έγραψε:
> On Dec 26, 2007 8:43 AM, Achilleas Margaritis <axilmar at otenet.gr> wrote:
>> Do finalizers run at exit, in version 7.0? although my finalizers
>> register correctly, they are not invoked at exit.
> 
> You know .. there is a ton of documentation and papers written by Hans
> out there.  You could try reading them:
> 
> http://portal.acm.org/citation.cfm?id=604153
> 
> In short: running finalizers at program exit is the *wrong* thing to do.
> 
> The fundamental difficulty is that the GC will finalizer objects only
> in a dependency-safe order, but end of program cleanup has to run all
> cleanup actions immediately and thus has to ignore dependencies.  Thus
> finalization and cleanup are totally different things.
> 
> What you should do is have your own mechanism to clean up your objects
> at program exit.  If one of those objects is garbage collected first
> then the finalizer needs to remove it from the list of objects to be
> cleaned up.  And be *extremely* careful of race conditions.
> Finalizers are hard, especially ones run synchronously by the GC.  We
> have half a dozen finalizers in our system and I think every single
> one of them has turned out to have a race condition bug in various
> ways, often after months of active use in the field.  They are VERY
> VERY hard to track down.



More information about the Gc mailing list