[Gc] Re: Do finalizers run at exit?

David Jones dej at inode.org
Fri Dec 28 17:43:02 PST 2007


On Friday 28 December 2007 11:08, Achilleas Margaritis wrote:

> > Even in Java, with a good generational GC, a
> > long-running server may have no need to do a full-world collection if the
> > generational collections are sufficient to provide enough memory to run.
>
> That's why you can invoke a manual collection when required.

In general, that could be a very expensive solution if you have a large heap.

In addition, a GC may choose not to free objects immediately, so a single GC 
call may not suffice.  I think the Boehm GC actually works this way.  This 
doesn't mean the GC leaks - it will reclaim all unreachable objects.  
Eventually.

> > 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.
>
> Then can I assume you have never made a program in which a resource must
> be shared between its heap-allocated objects!!! :-)

I have never written a program where an object that is designed to potentially 
become unreachable has held a resource for some period of time.  But then 
again, I doubt the correctness of such programs.  There are ways to manage 
what appears to be a shared resource without holding low-level resources for 
a long time.


More information about the Gc mailing list