我在一个 Java 应用程序上工作,该应用程序由(迄今为止)一个常规窗口(JFrame)和一个由菜单项首先调用的 JDialog 组成:
public class MainWindow {
private JFrame frame;
public MyDialog dialog;
/* ... */
private void initialize() {
mnNew = new JMenuItem("New...");
mnNew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dialog = new MyDialog();
}
});
}
}
并MyDialog
定义如下:
public class MyDialog extends JDialog {
public MyDialog() {
/* ... */
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
MyDialog.this.dispatchEvent(new WindowEvent(MyDialog.this,
WindowEvent.WINDOW_CLOSING));
MainWindow.window.matchMaker = null;
}
});
/* ... */
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setVisible(true);
}
}
一切正常,但我的任务管理器报告每次我打开然后关闭 MyDialog 时,程序都会消耗越来越多的内存。为什么?