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

Parent.getStylesheets().add(xxx) will cause a memory leak

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • 8
    • 7u6
    • javafx
    • Windows 7

      java version "1.7.0_11"
      Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
      Java HotSpot(TM) Client VM (build 23.6-b04, mixed mode, sharing)

      ------------------------------
      main.css (bg.png size: 85.2K)
      ------------------------------
      #bg
      {
          -fx-background-image : url('images/bg.png');
          -fx-background-size: stretch;
          -fx-background-position: left top;
          -fx-background-repeat: no-repeat;
      }

      -------------------------------------
      CssMemoryLeakTest.java
      -------------------------------------
      public class CssMemoryLeakTest extends Application {

          private StackPane root;
          private Button btn;

          @Override
          public void start(Stage primaryStage) {
              btn = new Button();
              btn.setText("Say 'Memory Leak'");
              btn.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                      VBox box = new VBox();
                      box.getStylesheets().add(getClass().getResource("resource/main.css").toExternalForm());
                      box.setId("bg");
                      root.getChildren().setAll(box, btn);
                  }
              });

              root = new StackPane();
              root.getChildren().add(btn);

              Scene scene = new Scene(root, 300, 250);

              primaryStage.setTitle("Hello World!");
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }


      ----------------------------------------

      It just took 4MB at the begining,
      after clicking the button 20 times, the memory increase to 200MB

      But, applying the same css file to the Scene, that would not happen


      BTW: It took me 2 days to locate this problem... orz

            dgrieve David Grieve
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: