JDK-8276917 : Memory Leak caused by MenuBarButton in ControlAcceleratorSupport
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: openjfx17
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2021-11-09
  • Updated: 2021-11-10
  • Resolved: 2021-11-10
Related Reports
Duplicate :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)

Windows 10 Pro 64-bit

A DESCRIPTION OF THE PROBLEM :
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run attached sample.
2. Click on the button "change scene" 
3. Take a heap dump and count the number of "MenuBarButton" 

Although MenuBar has been removed from the scene, the reference to MenuBarButton is still in ControlAcceleratorSupport#sceneChangeListenerMap

---------- BEGIN SOURCE ---------- 
import com.sun.javafx.scene.control.ControlAcceleratorSupport;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class TestFx
{

    public static void main( String[] args )
    {
        Application.launch( FxApp.class, args );
    }

    public static class FxApp extends Application
    {
        @Override
        public void start( final Stage primaryStage ) throws Exception
        {
            System.err.println( System.getProperty( "javafx.version" ) );
            MenuBar bar = createMenuBar( "Test1" );
            MenuBar bar2 = createMenuBar( "Test2" );
            MenuBar bar3 = createMenuBar( "Test3" );
            MenuBar bar4 = createMenuBar( "Test4" );

            Button button = new Button( "change scene" );

            BorderPane pane = new BorderPane( button );
            pane.getChildren()
                .addAll( bar, bar2, bar3, bar4 );
            button.setOnAction( ( ActionEvent event ) -> removeMenuBars( pane ) );
            primaryStage.setScene( new Scene( pane, 800, 600 ) );
            primaryStage.show();
        }

        private void removeMenuBars( BorderPane aBorderPane )
        {
            aBorderPane.getChildren()
                .clear();
        }
    }

    private static MenuBar createMenuBar( String aName )
    {
        MenuBar bar = new MenuBar();
        Menu menu = new Menu( aName );
        MenuItem item = new MenuItem( aName );
        menu.getItems()
            .add( item );
        bar.getMenus()
            .add( menu );
        return bar;
    }
}
---------- END SOURCE ---------- 


FREQUENCY : always



Comments
Duplicate of JDK-8274022
10-11-2021