-
Bug
-
Resolution: Duplicate
-
P5
-
None
-
5.0
-
x86
-
windows_xp
FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
Sample program doesn't release memory.
The bug is similar to bug ID 4193196 except that the fix was not ported to JPopupMenu
See http://weblogs.java.net/blog/timboudreau/archive/2005/04/writing_memory.html for details.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class MyFrame extends javax.swing.JFrame {
MenuAction menuAction = new MenuAction();
public MyFrame() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBounds (20, 20, 300, 300);
getContentPane().addMouseListener (new MouseAdapter() {
public void mouseReleased (MouseEvent me) {
getPopupMenu().show((Component) me.getSource(), me.getX(), me.getY());
}
});
}
JPopupMenu getPopupMenu() {
JPopupMenu menu = new JPopupMenu();
menu.add (new JMenuItem (menuAction));
return menu;
}
static final class MenuAction extends AbstractAction {
public MenuAction() {
putValue (Action.NAME, "Do Something");
}
public void actionPerformed (ActionEvent ae) {
System.out.println("Action performed");
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
One possible workaround removes the memory leak but removes some functionality.
Extend JPopupMenu and override JPopupMenu.createActionComponent:
protected JMenuItem createActionComponent(Action a) {
JMenuItem mi = new JMenuItem((String)a.getValue(Action.NAME),
(Icon)a.getValue(Action.SMALL_ICON));
mi.setHorizontalTextPosition(JButton.TRAILING);
mi.setVerticalTextPosition(JButton.CENTER);
mi.setEnabled(a.isEnabled());
return mi;
}
A DESCRIPTION OF THE PROBLEM :
Sample program doesn't release memory.
The bug is similar to bug ID 4193196 except that the fix was not ported to JPopupMenu
See http://weblogs.java.net/blog/timboudreau/archive/2005/04/writing_memory.html for details.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class MyFrame extends javax.swing.JFrame {
MenuAction menuAction = new MenuAction();
public MyFrame() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBounds (20, 20, 300, 300);
getContentPane().addMouseListener (new MouseAdapter() {
public void mouseReleased (MouseEvent me) {
getPopupMenu().show((Component) me.getSource(), me.getX(), me.getY());
}
});
}
JPopupMenu getPopupMenu() {
JPopupMenu menu = new JPopupMenu();
menu.add (new JMenuItem (menuAction));
return menu;
}
static final class MenuAction extends AbstractAction {
public MenuAction() {
putValue (Action.NAME, "Do Something");
}
public void actionPerformed (ActionEvent ae) {
System.out.println("Action performed");
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
One possible workaround removes the memory leak but removes some functionality.
Extend JPopupMenu and override JPopupMenu.createActionComponent:
protected JMenuItem createActionComponent(Action a) {
JMenuItem mi = new JMenuItem((String)a.getValue(Action.NAME),
(Icon)a.getValue(Action.SMALL_ICON));
mi.setHorizontalTextPosition(JButton.TRAILING);
mi.setVerticalTextPosition(JButton.CENTER);
mi.setEnabled(a.isEnabled());
return mi;
}
- duplicates
-
JDK-4626632 Various containers for Action throw NPE when PropChgEvent has null newValue
- Resolved