-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
5.0
-
Cause Known
-
x86
-
windows_xp
FULL PRODUCT VERSION :
Java 1.5.0 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
ADDITIONAL OS VERSION INFORMATION :
Window XP
A DESCRIPTION OF THE PROBLEM :
In the add method of JMenu, the accessibleParent of a JMenuItem is set to be the JMenu. However, the remove method does not unregister the accessibleParent. This causes a memory leak if a reference ot the JMenuItem is kept even if the JMenuItem is removed from the JMenu-- the JMenu cannot be garbage collected, and all other JMenuItems that are parented to the JMenu will also be kept.
Here is the add method:
public JMenuItem add(JMenuItem menuItem) {
AccessibleContext ac = menuItem.getAccessibleContext();
ac.setAccessibleParent(this);
ensurePopupMenuCreated();
return popupMenu.add(menuItem);
}
Here is the remove method:
public void remove(int pos) {
if (pos < 0) {
throw new IllegalArgumentException("index less than zero.");
}
if (pos > getItemCount()) {
throw new IllegalArgumentException("index greater than the number of items.");
}
if (popupMenu != null)
popupMenu.remove(pos);
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Populate a menu with several menu items (one of which you keep a reference to). Remove all menu items from the menu. The menu and other menu items still will not be garbaged collected because of the 1 that you have a reference to.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Calling remove should unregister the accessibleParent.
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Either set the accessibleParent to null or add the menu item (which you are keeping a reference to) to a dummy menu just to cause the accessibleParent to switch.
Java 1.5.0 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
ADDITIONAL OS VERSION INFORMATION :
Window XP
A DESCRIPTION OF THE PROBLEM :
In the add method of JMenu, the accessibleParent of a JMenuItem is set to be the JMenu. However, the remove method does not unregister the accessibleParent. This causes a memory leak if a reference ot the JMenuItem is kept even if the JMenuItem is removed from the JMenu-- the JMenu cannot be garbage collected, and all other JMenuItems that are parented to the JMenu will also be kept.
Here is the add method:
public JMenuItem add(JMenuItem menuItem) {
AccessibleContext ac = menuItem.getAccessibleContext();
ac.setAccessibleParent(this);
ensurePopupMenuCreated();
return popupMenu.add(menuItem);
}
Here is the remove method:
public void remove(int pos) {
if (pos < 0) {
throw new IllegalArgumentException("index less than zero.");
}
if (pos > getItemCount()) {
throw new IllegalArgumentException("index greater than the number of items.");
}
if (popupMenu != null)
popupMenu.remove(pos);
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Populate a menu with several menu items (one of which you keep a reference to). Remove all menu items from the menu. The menu and other menu items still will not be garbaged collected because of the 1 that you have a reference to.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Calling remove should unregister the accessibleParent.
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Either set the accessibleParent to null or add the menu item (which you are keeping a reference to) to a dummy menu just to cause the accessibleParent to switch.
- relates to
-
JDK-5022501 Accessibility code in Swing is not encapsulated in protected inner classes
-
- Resolved
-