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

macOS: Memory leak with MenuItem when Menu.useSystemMenuBar(true) is used

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • jfx22
    • jfx11, jfx21
    • javafx
    • None

    Description

      On macOS, when MenuBar.setUseSystemMenuBar set to true, there is a memory leak of javafx.scene.control.MenuItem and com.sun.glass.ui.MenuItem instances (among others), that can be seen if you remove and add MenuItems repetitively.
       
      The attached test application can reproduce the issue. It iterates 100 times with a delay of 0.1 second.

      To reproduce, just start the app, wait around 10 seconds, and see the output:
      Live MenuItems: 101

      This doesn't happen when MenuBar.setUseSystemMenuBar is false. In this case, as expected:
      Live MenuItems: 1

      Running VisualVM after the test, and doing a heap dump and filter Objects on "menu" shows the leak on different objects (See heapdump-menu.png)

      Also, the GC root points a JNI reference (See gc-root.menuitem1.png)

      which might indicate that a native object is not freed after the (Java) MenuItem is removed. Enabling native debug logs also indicates that dealloc (in mac/GlassMenu.m) is never called.

      The issue happens on any macOS architecture and with any JavaFX version.

      Attachments

        Issue Links

          Activity

            People

              jvos Johan Vos
              jpereda Jose Pereda
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: