Ginny Schmidt schrieb:

> We are working on an applet project (JDK 1.1.8 trying to go to 1.2) that has
> memory problems. I've read about
> various bug reports at the SUN developer connection website where garbage
> collection does not always take place correctly. Other than setting a JFrame or
> JDialog to null after it is disposed, what other things can you do to help the
> garbage collector to do it's work?

In general, you have to remove all references from longer living objects to
your short living objects. As for Swing, this could mean:

1. Call removeXXXListener on all your objects if they are listeners to any
Swing models or views.
2. Null out all references from Swing objects to you objects, especially from
Swing views to your models - for example from a JTable to your custom table
model by calling setModel(new DefaultTableModel()) on the JTable.
3. Let text components transfer their focus to another component.
4. Call removeAll() when destroying containers.
5. Use weak references if possible.
6. Do not use finalizer extensively for cleaning up. With HotSpot 1.3, I observed
some hundred thousands of Finalizer objects hanging around if the VM was under
heavy load with lots of objects created and destroyed. As the Finalizer objects
refer
the objects to be finalized and almost no Finalizer ran, the VM soons gets out of
memory.
7. Use a profiling tool to identify the references which keep objects alive.

Not all these operations are required, but all help the garbage collector
to free memory as fast as possible.

> Calling System.gc() doesn't seem to help
> either.

That's what I observed, too.

--
Christian Pesch - Software Engineer
[EMAIL PROTECTED] - fon +49.40.325587.505  fax .999
CoreMedia AG - www.coremedia.com - 0700-COREMEDIA
Erste Brunnenstra�e 1, 20459 Hamburg, Germany

CoreMedia - Think ahead! We're there.



_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to