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

Memory leak in JavaFX ProgressIndicator

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 8u60
    • 8u40, 8u60
    • javafx
    • None
    • Windows 7 x64

    • Not verified

      Issue Description
      =============
      Whenever you create an indeterminate ProgressIndicator, it will stay in memory forever and with it everything that has a a reference to it.

      This issue is quite critical since all our dialogs have kind of a "busy-glass-pane" showing an indeterminate progress indicator asa visual cue that "soemthing" is in progress and disabling mouse/key-inputs, etc. However, there's a workaround for it...

      Workaround
      =========
      Apparently the ProgressIndicator is kept due to an infinite cycle-loop animation. So actually it will be OK memorywise to set progress to 1 (i.e. 100%) before getting rid of it.

      Example
      =======
      Fire up and see that once you open a dialog a progress-indicator will be created and after you close the dialog it will never be GC'd.


      package sandbox;

      import javafx.application.Application;
      import javafx.geometry.Insets;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ButtonBar.ButtonData;
      import javafx.scene.control.ButtonType;
      import javafx.scene.control.Dialog;
      import javafx.scene.control.ProgressIndicator;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class ProgressIndicatorMemoryLeak extends Application {
      public static void main(String[] args) {
      launch(args);
      }

      @Override
      public void start(Stage primaryStage) throws Exception {

      Button openDialog = new Button("Open Dialog");
      openDialog.setOnAction(ae -> {

      ButtonType loginButtonType = new ButtonType("Login", ButtonData.OK_DONE);
      Dialog<String> dialog = new Dialog<>();
      dialog.getDialogPane().getButtonTypes().add(loginButtonType);

      ProgressIndicator indicator = new ProgressIndicator();
      BorderPane content = new BorderPane(indicator);
      content.setPadding(new Insets(20));
      dialog.getDialogPane().setContent(content);

      dialog.show();
      });

      BorderPane bp = new BorderPane();
      bp.setCenter(openDialog);

      Scene scene = new Scene(bp, 300, 300);
      primaryStage.setTitle("Memory Leak");
      primaryStage.setScene(scene);
      primaryStage.show();
      }
      }

            jgiles Jonathan Giles
            smorandijfx Stefano Morandi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: