-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
7
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
If setClosed(true) is not called on each JInternalFrame when removing them from a JDesktopPane, a leak occurs due to code in BasicInternalFrameUI.
The code in the method "propertyChange" in the internal class "Handler" in the class BasicInternalFrameUI adds and removes a component listener based on certain events. But it only removes the listener if it receives a "closed" property event. If the JInternalFrame is removed by calling desktop.removeAll() (or similar functions) without first calling setClosed(true), then a memory leak occurs because the listener is never removed.
If it is intended, then the documentation for JDesktopPane should be updated to reflect this.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Add an internal frame to a JDesktopPane
2. Make it active and selected
3. Remove the internal frame without calling setClosed(true) first
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When calling removeAll() or remove() the listener should be removed as if setClosed(true) had been called.
ACTUAL -
When calling removeAll() or remove(), the listener is not removed.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public static void main(final String[] args) throws Exception
{
JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JDesktopPane pane = new JDesktopPane();
frame.add(pane);
JInternalFrame testFrameA = new JInternalFrame("windowA");
pane.add(testFrameA);
pane.setSelectedFrame(testFrameA);
System.out.println("after add frame:");
System.out.println(Arrays.toString(pane.getComponentListeners()));
// When this is uncommented, there are no component listeners on the pane after the call to removeAll()
//testFrameA.setClosed(true);
pane.removeAll();
System.out.println("after remove frame:");
System.out.println(Arrays.toString(pane.getComponentListeners()));
frame.dispose();
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Call setClosed(true) on all internal frames you intend to remove.
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
If setClosed(true) is not called on each JInternalFrame when removing them from a JDesktopPane, a leak occurs due to code in BasicInternalFrameUI.
The code in the method "propertyChange" in the internal class "Handler" in the class BasicInternalFrameUI adds and removes a component listener based on certain events. But it only removes the listener if it receives a "closed" property event. If the JInternalFrame is removed by calling desktop.removeAll() (or similar functions) without first calling setClosed(true), then a memory leak occurs because the listener is never removed.
If it is intended, then the documentation for JDesktopPane should be updated to reflect this.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Add an internal frame to a JDesktopPane
2. Make it active and selected
3. Remove the internal frame without calling setClosed(true) first
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When calling removeAll() or remove() the listener should be removed as if setClosed(true) had been called.
ACTUAL -
When calling removeAll() or remove(), the listener is not removed.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public static void main(final String[] args) throws Exception
{
JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JDesktopPane pane = new JDesktopPane();
frame.add(pane);
JInternalFrame testFrameA = new JInternalFrame("windowA");
pane.add(testFrameA);
pane.setSelectedFrame(testFrameA);
System.out.println("after add frame:");
System.out.println(Arrays.toString(pane.getComponentListeners()));
// When this is uncommented, there are no component listeners on the pane after the call to removeAll()
//testFrameA.setClosed(true);
pane.removeAll();
System.out.println("after remove frame:");
System.out.println(Arrays.toString(pane.getComponentListeners()));
frame.dispose();
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Call setClosed(true) on all internal frames you intend to remove.
- relates to
-
JDK-6802868 JInternalFrame is not maximized when maximized parent frame.
- Closed