[Gc] Re: Do finalizers run at exit?

S M Ryan wyrmwif at rawbw.com
Thu Dec 27 11:46:37 PST 2007

> And if you do that, you have no need for finalizers, period.  At  
> least I have
> yet to see a good use of finalizers in a well-designed and correct  
> program.

I create networks of asynchronous objects that pass messages. If an  
object is dropped from the network, it is eventually collected. I  
also have a thread lock with each object and that lock has to be  
explicitly released; I use a finaliser on the object to release the  

To know when the last the reference to an object is lost, I would  
need reference counts that can cope with loops. Or I can let the  
garbage collector tell me after the last reference lost. I keep  
unneeded thread locks longer than necessary, but it hasn't caused  
problems yet.

Finalisers work fine to release resources that can be allowed to  
linger, or exit unreleased, such as an open file descriptor (up to a  
point) but not an output buffer.

More information about the Gc mailing list