Submitted On 14-OCT-2002
cforster
Yes, this has been around forever... If you look in Swing code
you'll find that a ref to a single added JIF (last?) is always
held (forget where... haven't looked in a while).
I seem to remember (using OptimizeIt) that this only results in
a single persistent loss of <100K for the JDesktopPane
instance (presuming you add an InternalFrameListener for
closed(closing?) that clears any lingering refs, etc.). You'll
probably have at least one JIF on a showing JDesktop around
anyway & it will need its space. There are much bigger fish in
the sea (mem leaks) waiting to be caught...
Submitted On 17-OCT-2002
jamock
The following workaround to the above code seems to
correct the memory leak:
final InternalFrameListener iFrameListener = new
InternalFrameAdapter() {
public void internalFrameClosed(InternalFrameEvent
evt)
{
if (desktopPane.getAllFrames().length == 0)
KeyboardFocusManager.getCurrentKeyboardFocusManager
().clearGlobalFocusOwner();
}
};
Submitted On 20-JAN-2003
takisd
i've been fiddling with this for months now. this is what i've
noticed. yes there is a definite memory leak but for me occurs
more often on the very first frame added to the desktop.
THAT frame is never garbage collected (i'm using profilers).
i've also noticed that a particular internal frame i have
with 'heavy' components and listeners is not garbage
collected unless it is the second of these specific frames to
be opened - ie. subsequent frames of this type are collected
but never the first. i tried the work around listed and that
didn't seem to work. what i've done now is simply add an
empty internal frame to the desktop before any others and
remove it immediately after the add() method. it is never
garbage collected but minimises the memory leak to an empty
frame as opposed to one with many components. not much of
a work around but certainly mitigates the affects. i don't
notice any other issues - another frame added to an empty
desktop is ok as that first empty one is still hanging around.
Takis
Submitted On 20-JAN-2003
takisd
i've been fiddling with this for months now. this is what i've
noticed. yes there is a definite memory leak but for me occurs
more often on the very first frame added to the desktop.
THAT frame is never garbage collected (i'm using profilers).
i've also noticed that a particular internal frame i have
with 'heavy' components and listeners is not garbage
collected unless it is the second of these specific frames to
be opened - ie. subsequent frames of this type are collected
but never the first. i tried the work around listed and that
didn't seem to work. what i've done now is simply add an
empty internal frame to the desktop before any others and
remove it immediately after the add() method. it is never
garbage collected but minimises the memory leak to an empty
frame as opposed to one with many components. not much of
a work around but certainly mitigates the affects. i don't
notice any other issues - another frame added to an empty
desktop is ok as that first empty one is still hanging around.
Submitted On 16-MAR-2004
sudhakar_it
hi
Submitted On 19-DEC-2005
Violetta
I'm still experiencing this problem on 1.5.
Submitted On 21-OCT-2006
There is an easy solution, at least in mustang.
The problem is in DefaultDesktopManager.closeFrame,
if the next frame is null the framesCache of the JDesktopPane
is not refreshed and remains a reference to the closed InternalFrame
The correct
public void closeFrame(JInternalFrame f) {
JDesktopPane d = f.getDesktopPane();
if (d == null) {
return;
}
boolean findNext = f.isSelected();
Container c = f.getParent();
- JInternalFrame nextFrame = null;
- if (findNext) {
- nextFrame = d.getNextFrame(f);
try { f.setSelected(false); } catch (PropertyVetoException e2) { }
- }
if(c != null) {
c.remove(f); // Removes the focus.
c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
}
removeIconFor(f);
if(f.getNormalBounds() != null)
f.setNormalBounds(null);
if(wasIcon(f))
setWasIcon(f, null);
- if (nextFrame != null) {
- try { nextFrame.setSelected(true); }
- catch (PropertyVetoException e2) { }
- } else if (findNext && d.getComponentCount() == 0) {
- // It was selected and was the last component on the desktop.
- d.requestFocus();
- }
+ if (findNext) {
+ d.selectFrame(true);
+ }
}
With the call to d.selectFrame(true) at the end of the method, even if the
next frame don't exists, selectFrame calls verifyFrame, the framesCache
of the JDesktopPane is refreshed and the reference to the closed frame removed.
Submitted On 19-APR-2007
drokar
About the previous fix,
d.selectFrame(true) and d.getNextFrame(f) are not existing methods of JDesktopPane in JDK6 (Mustang)
Submitted On 19-APR-2007
drokar
I need a new pair of glass
forget my previous comment..... my mistake
Submitted On 28-NOV-2008
handsteiner
The priority is at least 2. the garbage collector has no chance to finalize the JInternalFrame. so if it is removed, the reference has to be nulled!!!
Same problems occures in the KeyboardFocusManager with static references and non static references in the current KeyboardFocusmanager who holds also unclearable references to components which are already removed.
if the handling with references is not well developed or designed, at least weakreferences should be used to prevent memory leaks!!!!!
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|