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

Memory leak when removing JInternalFrame from JDesktopPane

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 7u51
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.7.0_51"
      Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
      Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When a JInternalFrame is removed from its JDesktopPane, calling dispose() on that JInternalFrame does not remove the ComponentListener (javax.swing.plaf.basic.BasicInternalFrameUI.Handler) registered by the internal frame in the JDesktopPane.

      This causes a memory leak.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the given test class and see the output.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JDesktopPane;
      import javax.swing.JFrame;
      import javax.swing.JInternalFrame;
      import javax.swing.SwingUtilities;

      public class InternalFrameMemoryLeak {
      public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
      JDesktopPane pane = new JDesktopPane();
      JFrame frame = new JFrame("MemoryLeak");
      frame.setContentPane(pane);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(400, 300);
      frame.setVisible(true);

      //Create and destroy many internal frames.
      final int N = 100;
      for (int i = 0; i < N; ++i) {
      JInternalFrame f = new JInternalFrame();
      f.setSize(200, 100);
      f.setVisible(true);
      pane.add(f);

      f.setVisible(false);
      pane.remove(f);//<-------- If this line is removed, everything works fine.
      f.dispose();
      }

      //There must be no component listeners, but there are N.
      System.out.println(pane.getComponentCount() + " " + pane.getComponentListeners().length);
      }
      });
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Do not remove a JInternalFrame from the JDesktopPane - simply call JInternalFrame.dispose() instead.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: