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

Memory Leak when removing frames from JDesktopPane without calling setClosed()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 7
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description

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

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

      A DESCRIPTION OF THE PROBLEM :
      If setClosed(true) is not called on each JInternalFrame when removing them from a JDesktopPane, a leak occurs due to code in BasicInternalFrameUI.

      The code in the method "propertyChange" in the internal class "Handler" in the class BasicInternalFrameUI adds and removes a component listener based on certain events. But it only removes the listener if it receives a "closed" property event. If the JInternalFrame is removed by calling desktop.removeAll() (or similar functions) without first calling setClosed(true), then a memory leak occurs because the listener is never removed.

      If it is intended, then the documentation for JDesktopPane should be updated to reflect this.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Add an internal frame to a JDesktopPane
      2. Make it active and selected
      3. Remove the internal frame without calling setClosed(true) first


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      When calling removeAll() or remove() the listener should be removed as if setClosed(true) had been called.
      ACTUAL -
      When calling removeAll() or remove(), the listener is not removed.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public static void main(final String[] args) throws Exception
      {
      JFrame frame = new JFrame("test");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
      JDesktopPane pane = new JDesktopPane();
      frame.add(pane);
      JInternalFrame testFrameA = new JInternalFrame("windowA");
      pane.add(testFrameA);
      pane.setSelectedFrame(testFrameA);
      System.out.println("after add frame:");
      System.out.println(Arrays.toString(pane.getComponentListeners()));
      // When this is uncommented, there are no component listeners on the pane after the call to removeAll()
      //testFrameA.setClosed(true);
      pane.removeAll();
      System.out.println("after remove frame:");
      System.out.println(Arrays.toString(pane.getComponentListeners()));
      frame.dispose();
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Call setClosed(true) on all internal frames you intend to remove.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rupashka Pavel Porvatov (Inactive)
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: