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

Memory Leak issue with Charts / WeakReferences / Platform.accessibilityActiveProperty()

    XMLWordPrintable

Details

    Description

      Please refer to https://community.oracle.com/thread/3687884 for details.

      If you run the following code for a while, I noticed increasing memory consumption.

      A heap analysis shows especially two classes which have thousands of instances (and keep growing):
      1. java.lang.ref.WeakReference
      2. javafx.beans.property.BooleanPropertyBase$Listener

      After a heap analysis, it seems for me like something inside JavaFX is adding listeners to:

      Platform.accessibilityActiveProperty()

      but never removes them.



          import javafx.animation.Animation;
          import javafx.animation.KeyFrame;
          import javafx.animation.Timeline;
          import javafx.application.Application;
          import javafx.collections.FXCollections;
          import javafx.collections.ObservableList;
          import javafx.geometry.Insets;
          import javafx.scene.Scene;
          import javafx.scene.chart.NumberAxis;
          import javafx.scene.chart.StackedAreaChart;
          import javafx.scene.chart.XYChart;
          import javafx.scene.layout.Priority;
          import javafx.scene.layout.VBox;
          import javafx.stage.Stage;
          import javafx.util.Duration;
            
          public class TestApp4 extends Application {
              private static final int COUNT = 50;
            
              private final ObservableList<XYChart.Data<Number, Number>> data = FXCollections.observableArrayList();
            
              public static void main(String[] args) {
                  launch();
              }
            
              @Override
              public void start(Stage stage) throws Exception {
            
                  VBox root = new VBox();
                  root.setPadding(new Insets(50, 50, 50, 50));
            
                  NumberAxis timeAxis = new NumberAxis();
                  timeAxis.setMinorTickVisible(false);
                  timeAxis.setTickLabelsVisible(false);
                  timeAxis.setLabel("t");
                  NumberAxis memoryAxis = new NumberAxis();
                  memoryAxis.setLabel("X");
                  StackedAreaChart<Number, Number> stackedAreaChart = new StackedAreaChart<>(timeAxis, memoryAxis);
            
                  final ObservableList<XYChart.Series<Number, Number>> data = FXCollections.observableArrayList();
                    
                  XYChart.Series<Number, Number> series = new XYChart.Series<>(this.data);
                  data.add(series);
            
                  updateSeries();
            
                  stackedAreaChart.setData(data);
                  stackedAreaChart.setAnimated(false);
                  Timeline timeline = new Timeline(new KeyFrame(Duration.millis(100), actionEvent -> updateSeries()));
                  timeline.setCycleCount(Animation.INDEFINITE);
                  timeline.play();
            
                  VBox.setVgrow(stackedAreaChart, Priority.ALWAYS);
            
                  root.getChildren().add(stackedAreaChart);
            
                  Scene scene = new Scene(root);
                  stage.setScene(scene);
                  stage.show();
              }
            
              private void updateSeries() {
                  if (data.size() > COUNT) {
                      data.remove(0);
                  }
                  for (XYChart.Data<Number, Number> data : this.data) {
                      data.setXValue(data.getXValue().intValue() - 1);
                  }
                  data.add(new XYChart.Data<>(COUNT, Math.random()));
              }
          }

      Attachments

        Issue Links

          Activity

            People

              jgiles Jonathan Giles
              cschudtjfx Christian Schudt (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: