I work on a Java application consisting (as yet) of a regular Window (JFrame) and a JDialog called by a menuitem in the first:
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();
}
});
}
}
And MyDialog
is defined as follows:
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);
}
}
Everything works fine, but my Task Manager reports that each time I open and then close MyDialog, the program consumes more and more memory. Why?