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

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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 7u6
    • Fix Version/s: 8
    • Component/s: javafx
    • Labels:
    • Environment:

      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)

      Description

      ------------------------------
      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

        Attachments

          Activity

            People

            • Assignee:
              dgrieve David Grieve (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: