2

I have a weird behavior with the JOptionPane.showInputDialog(...) method (and other methods of JJOptionPane). The dialogs created never seem to die. When I call Window.getWindows() after the dialog has disappeared, the number of windows has increased!

Test this program and you see what I mean:

public static void main(String[] args) {
        final JFrame frame = new JFrame();
        final JPanel panel = new JPanel();
        final JButton button = new JButton("Show Dialog");
        panel.add(button);
        frame.add(panel);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                JOptionPane.showInputDialog(frame, "Enter some text : ");
                System.out.println(Window.getWindows().length);
            }
        });
        frame.setSize(400, 400);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
}

Can someone explain what is happening?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
paranoia25
  • 626
  • 1
  • 5
  • 23

1 Answers1

4

Someone understand what happens?

Window.getWindows() returns always every Top-Level Containers that are created (without containers returns !isDisplayable) in the current JVM, these containers never gone from JVM memory, nor be GC'ed, because they are came as resources from Native OS, more here

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • `Why` do you backtick `stuff` that's `not actually code` in your answers? We have **`bold`** `and` *`italics`* for that. – wchargin Nov 08 '13 at 03:20