[3059] in java-interest

home help back first fref pref prev next nref lref last post

Re: Finalize()

daemon@ATHENA.MIT.EDU (Jim Graham)
Sat Oct 28 00:03:09 1995

Date: Fri, 27 Oct 1995 19:25:44 -0700
From: flar@bendenweyr.Eng.Sun.COM (Jim Graham)
To: java-interest@java.Eng.Sun.COM, richwill@infoscape.com


> The final few sentences is this footnote are somewhat alarming.   
> How can finalize() be used for ANYTHING if it isn't reliably called?

Since the finalize() method is called from the garbage collector and
since the actions and timing of the garbage collector or implementation
dependent, you shouldn't rely on any consistency from it to invoke
your finalize methods.

Keep in mind that if the user has enough memory and if his current
running heap usage is fairly stable it may be a very long time until
the next GC cycle and so your finalize() method may not be called for
a *long* time.  In the meantime if you need some system resource that
an unfinalized object is wasting, you may be out of luck if you were
depending on the garbage collector to finalize your class and restore
the system resources.

This is why when we call your paint and update methods with a Graphics
object we explicitly call the dispose() method on the object after you
are done painting even though dispose() is also called from the
finalization method.  If we relied on the garbage collector to dispose
the GC's then we might have an indeterminate number of system GC
objects being wasted attached to old unreachable (but not yet
collected/finalized) Graphics objects...

				...jim
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post