Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6877809

Memory leak in JDialog

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 6u16
    • client-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_03"
      Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
      Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      JDialog is not released from the memory after closed it, it's getting cleared only if we navigated some other window and come back to the main screen.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a frame
      2. Create a dialog by giving frame as a parent
      3. Show frame
      4. Show dialog
      5. Close dialog
      6. Check the owned windows of the frame

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Dialog's memory should get released from the heap
      ACTUAL -
      Dialog's memory is not getting cleared until we navigate to some other application

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Window;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.util.Arrays;

      import javax.swing.JButton;
      import javax.swing.JDialog;
      import javax.swing.JFrame;
      import javax.swing.JPanel;

      public class DialogTest {
          public static void main(String[] args) {
              final JFrame mainFrame = new JFrame("Main Frame");
              mainFrame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
              mainFrame.setSize(500, 400);
              mainFrame.setLocationRelativeTo(null);
              
              JButton showDialog = new JButton("Show Dialog");
              showDialog.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      JDialog dialog = new JDialog(mainFrame, "Dialog");
                      dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                      dialog.setSize(400, 300);
                      dialog.setLocationRelativeTo(null);
                      dialog.setVisible(true);
                  }
              });

              JButton invokeGC = new JButton("GC");
              invokeGC.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      System.gc();
                  }
              });
              
              JButton printOwnedWindows = new JButton("Print Owned windows");
              printOwnedWindows.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      Window[] ownedWindows = mainFrame.getOwnedWindows();
                      System.out.println(Arrays.toString(ownedWindows));
                  }
              });
              
              JPanel panel = new JPanel();
              panel.add(showDialog);
              panel.add(invokeGC);
              panel.add(printOwnedWindows);
              mainFrame.add(panel);
              
              mainFrame.setVisible(true);
          }
      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: