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

XYChart produces OutOfMemoryError: Java heap space

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7u6
    • Fix Version/s: 8
    • Component/s: javafx

      Description

      From this discussion:

      https://forums.oracle.com/forums/thread.jspa?threadID=2509317&tstart=0

      There's a bug in Chart Controls. Appearently, if you use the same Data collection in more than one chart.


      Here's the code from forum:
      Add two charts, then add a data point. The application crashes.


      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.chart.AreaChart;
      import javafx.scene.chart.NumberAxis;
      import javafx.scene.chart.XYChart;
      import javafx.scene.control.Button;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

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

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

              final Button button = new Button("Add new chart");
              final Button addDataButton = new Button("Add another data point");

              final ObservableList<XYChart.Data<Number, Number>> series1Data = FXCollections.observableArrayList();
              series1Data.add(new XYChart.Data<Number, Number>(0, 0));
              final VBox root = new VBox(10);
              HBox buttons = new HBox(5);
              buttons.getChildren().addAll(button, addDataButton);
              root.getChildren().add(buttons);

              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      NumberAxis timeAxis = new NumberAxis();
                      NumberAxis memoryAxis = new NumberAxis();

                      AreaChart<Number, Number> chart = new AreaChart<Number, Number>(timeAxis, memoryAxis);

                      final ObservableList<XYChart.Series<Number, Number>> data = FXCollections.observableArrayList();
                      chart.setData(data);

                      XYChart.Series<Number, Number> series1 = new XYChart.Series<Number, Number>();
                      data.add(series1);


                      series1.setData(series1Data);

                      root.getChildren().add(chart);
                  }
              });

              addDataButton.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent event) {
                      double x = series1Data.size();
                      double y = Math.log(x + 1);
                      series1Data.add(new XYChart.Data<Number, Number>(x, y));
                  }
              });

              stage.setScene(new Scene(root, 400, 800));

              stage.show();
          }

      }

        Attachments

          Activity

            People

            • Assignee:
              psomashe Parvathi Somashekar (Inactive)
              Reporter:
              cschudtjfx Christian Schudt (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved:
                Imported: