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
Finalization On Exit
Posted by Bill Venners on 03 Jun 1998, 1:32 PM
> 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
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.