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

MenuBar/MenuBarSkin causing memory leak if removed from a scene

    XMLWordPrintable

Details

    • x86_64
    • windows_7

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      MenuBar/MenuBarSkin causing memory leak if tried to be removed from a scene. See code part from jdk8u121 code of com.sun.javafx.scene.control.skin.MenuBarSkin (from line 371):
      Utils.executeOnceWhenPropertyIsNonNull(control.sceneProperty(), (Scene scene) -> {
                  scene.getAccelerators().put(acceleratorKeyCombo, firstMenuRunnable);

                  // put focus on the first menu when the alt key is pressed
                  scene.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
                      if (e.isAltDown() && !e.isConsumed()) {
                          firstMenuRunnable.run();
                      }
                  });
              });

      This is the most probable cause that the event handler is not weak so it is never removed so if menubar applied on a scene graph (e.g. via FXML).

      This issue is raised and solved in openjdk: https://bugs.openjdk.java.net/browse/JDK-8166950

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a stage with a scene and within that a control that has internal MenuBar; after disposing the control it will remove in memory, as menubar will be refer to the topmost scene.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Control and MenuBar should be garbage collected.
      ACTUAL -
      Control and MenuBar stays in memory after GC

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      No, we do not use MenuBar for sections of disposable content.

      Attachments

        Issue Links

          Activity

            People

              pmangal Priyanka Mangal (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: