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

Creating ScrollPane with same content component causes memory leak

XMLWordPrintable

    • b04
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Microsoft Windows [Version 10.0.18363.1198]
      openjdk version "11.0.5" 2019-10-15
      OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)
      OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.5+10, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      Creating ScrollPane with same content component causes memory leak until the component is removed from the scene.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Open provided ScrollPaneLeakTest.
      2. Keep pressing the "test' button.
      3. Invoke GC and observe the ScrollPane count in memory analyzing tools - jvisualvm or Eclipse MAT.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      After 3. the ScrollPane count should be 1.
      ACTUAL -
      Aftery 3. every time the button is pressed, the ScrollPane is created, it is present in heap dump.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.ScrollPane;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class ScrollPaneLeakTest
      {

          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" ) );
                  final var testLabel = new Label( "Test label" );

                  final var rootPane = new BorderPane();
                  final var testButton = new Button( "test" );
                  testButton.setOnAction( e -> {
                      rootPane.setCenter( new ScrollPane( testLabel ) );
                  } );
                  rootPane.setTop( testButton );
                  rootPane.setCenter( new ScrollPane( testLabel ) );
                  primaryStage.setScene( new Scene( rootPane, 800, 600 ) );
                  primaryStage.show();
              }

          }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      no workaround

      FREQUENCY : always


        1. Screen Shot 2022-09-06 at 16.08.05.png
          184 kB
          Andy Goryachev
        2. ScrollPaneLeakTest.java
          1 kB
          Praveen Narayanaswamy

            angorya Andy Goryachev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: