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
Swing and AWT memory leaks
Posted by Adrian Dickin on 23 Feb 1999, 6:52 AM
We've had problems with memory leaks and tracked all of ours down using
OptimizeIt. Some of the problems were due to bugs/problems within AWT
We had a main screen that added panels using GridBagLayout. The
problem here was that internally GridBagLayout uses a HashTable.
When a panel was removed it wasn't removed from the hash table,
so it would never be GC. In bug parade this is Bug Id 4170095
and was fixed 1999-02-01.
These hang around because they register for keystrokes,
within BasicToggleButtonUI, and so their parents etc. are never
We fixed it by calling resetKeyboardActions() on every
JCheckBox/JRadioButton. In bug parade this is Bug Id 4129207
and is still in progress.
> I have observed that AWT and Swing components that are added
> to a top-level component never gets garbage collected as long
> as the top-level component exists(i.e. not been made null).
> We have developed an MDI application using Swing.This app
> contains child windows(JInternalFrames) and dialogs(which are
> also designed as JInternalFrames).Upon bringing such JInternalFrames
> 15-20 times in a 64MB system(WIN - 95) the Application throws
> OutOfMemoryError.And after sometime the whole app goes for a toss.
> I believe the JVM before throwing an OutOfMemoryError should run the
> GC and any unreferenced object on the heap should be GC'ed.Let me
> tell you here that our reference to these JInternalFrames are made
> null after these windows are closed.
> I suspect some of the AWT & Swing classes might be keeping
> reference to this objects which they never seem to release.
> I would request you all to reply soon if you have any idea
> why this is happening? If u want I can provide you with test codes.
> Thanks in advance
- hi suresh December 19, 2000 at 10:28 AM