On Sat, 2003-02-22 at 17:38, Jacob Hookom wrote:
> GC'ing is done in parallel now... as far as I know, it won't halt all
> threads... it's not as bad with the new JVM's.

Yes, AFAIK, GC will not halt newer JVMs. However, there are still many
many problems with finlizers and System.gc():

1. Finalizers are called when the object is actually collected.  There
are absolutely no guarantees on when this will happen, if ever.  It is
perfectly within spec for a GC to wait forever to collect any particular
object.  Also, if the JVM proc is kill -9'ed, then it may exit without
calling any finalizers.  See also problem #3 below.  Will your data
still be in a valid state if that happens?

2. With very few exceptions, calling System.gc() is a bad idea.  The JVM
knows what it's doing better than you do.

3. Finalizers have a problem within the class hierarchy: subclasses do
not automatically call super.finalize(), so if you write a class which
is non-final, and someone else subclasses, its finalizer might not even
be called when the object is gc'ed.  Will your data still be in a valid
state?

4. From what I can tell, the main reason to have a finalize() method is
if your object has some kind of JNI resources that it needs to clean up
outside of the JVM.  JNI itself has less and less purpose as JVMs have
become as fast as, or even faster than, native code.  Of course, JNI
will always be needed for some things, so this is a legitimate use of
finalize().

So... bottom line: Unless you are doing something like using JNI, don't
use finalizers.

One other poster sugested that it is a good idea to be careful about
creating and then abandoning small objects.  Modern gcs are very very
fast.  I wouldn't worry about this at all unless it is clearly shown to
be a performance problem in real life.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to