The Artima Developer Community
Sponsored Link

Legacy Design Forum
Finalization and Cleanup



This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.



Posted by Michel Feinstein on July 26, 1999 at 2:22 PM

This article says that runFinalizersOnExit is deprecated because of Thread use. It seems to me that the result of this implies that programmers should explicitly close non-memory resource and not expect some c-like destructor is going to do this for them. Does this sound right?

> > Are there any required actions of the jvm when the java process
> > is interrupted (like using ctrl-c). There doesn't seem to be.

> I don't know for certain. I would expect that if you have
> called runFinalizersOnExit(true) that the finalizers should
> be run even when going down because of an interrupt. Does
> anyone know for sure?

> > Also, upon normal exit, finalizers may not run even if the
> > object is no longer referenced and even if a System.gc() is
> > issued.
> >
> Yup. System.gc() is always just a hint to the VM that
> this would be a good time to do garbage collection. The VM
> can decide what to do. (Some VMs may decide to always GC when
> System.gc() is called. Others may completely ignore
> System.gc(). Others may land somewhere in between.)

> > You might want to mention the System.runFinalizersOnExit( )
> > method, which forces finalizers to be run upon normal system exit.
> > These seem to run even if the object is still referenced.

> I thought I mentioned that...Yes, I just checked and this
> is already mentioned in the article, where I said:

> One more rule of thumb about finalizers concerns objects left on the heap at the end of the application's lifetime. By default, the
> garbage collector will not execute the finalizers of any objects left on the heap when the application exits. To change this
> default, you must invoke the runFinalizersOnExit() method of class Runtime or System, passing true as the single
> parameter. If your program contains objects whose finalizers must absolutely be invoked before the program exits, be sure to
> invoke runFinalizersOnExit() somewhere in your program.

> bv


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us