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

[Charts,CSS] Memory leak in PieChart



    • Bug
    • Resolution: Fixed
    • P2
    • 8u40
    • 8u20
    • javafx
    • java version "1.8.0_20"
      Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
      Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)


      When updating a PieChart using any type of thread will create a heap out of memory exception. Please look at the code example attached with this bug.

      To speed things up please use the -Xms16m -Xmx16m setting to the virtual machine. Below is the example code. Please note that the code is a great example of cut-and-past coding.

      -------- FX ------------------------------------------------------------------------
      <AnchorPane fx:id="rootPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="446.0" prefWidth="546.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="com.zebware.PieController">
          <VBox id="VBox" alignment="CENTER" layoutX="22.0" layoutY="0.0" spacing="5.0">
              <Label text="Sample PieChart memory test" />
              <PieChart fx:id="storageAllocation" legendSide="RIGHT" animated="false" labelsVisible="false" startAngle="90.0" />

      -- Java--------------------------------------------------------------------------------
      import java.net.URL;
      import java.util.ArrayList;
      import java.util.List;
      import java.util.Random;
      import java.util.ResourceBundle;

      import javafx.animation.AnimationTimer;
      import javafx.fxml.FXML;
      import javafx.fxml.Initializable;
      import javafx.scene.chart.PieChart;
      import javafx.stage.Stage;

      public class PieController extends Stage implements Initializable {

          @FXML private PieChart storageAllocation;

          private StorageUsageService sus = new StorageUsageService();
          private long lastUpdate = 0;

          public void initialize(URL arg0, ResourceBundle arg1) {

          public final void executePeriodicBackgroundTask() {
              AnimationTimer timer = new AnimationTimer() {

                  public void handle(long now) {
                      System.out.println("Update: " + (now - lastUpdate));
                      lastUpdate = now;



          // ---------------------------------------- Inner update class

          private class StorageUsageService {

              Random ran = new Random();

              private class StorageNotConfigured extends Exception {
                  private static final long serialVersionUID = 137978200558303650L;

              public void succeeded() {
                  List<PieChart.Data> value = createTask();

              protected List<PieChart.Data> createTask() {

                          List<PieChart.Data> chartData = new ArrayList<PieChart.Data>();

                          try {
                          } catch (StorageNotConfigured e) {
                              // pool is not configured, no problem

                          return chartData;


              private PieChart.Data fetchAndAssemblePoolUsage() throws StorageNotConfigured {

                  return assembleChartData("Legend 1", ran.nextLong());

              private List<PieChart.Data> fetchAndAssembleShareUsage() {
                  List<PieChart.Data> chartData = new ArrayList<PieChart.Data>();


                  return chartData;

              private PieChart.Data assembleFolderAllocatedSizeData() {
                  return assembleChartData("Legend 2", ran.nextLong());

              private PieChart.Data assembleVolumeAllocatedSizeData() {
                  return assembleChartData("Legend 3", ran.nextLong());

              private PieChart.Data assembleChartData(String textID, long size) {
                  return new PieChart.Data(textID, size);


      ---- Starter class ----------------------------------------------------------------

      import javafx.application.Application;
      import javafx.fxml.FXMLLoader;
      import javafx.scene.Scene;
      import javafx.scene.layout.AnchorPane;
      import javafx.stage.Stage;

      public class FxTableApplication extends Application {

          public static Stage primaryAppStage = null;
          public void start(Stage primaryStage) {
              try {
                  if( primaryAppStage == null ){
                      primaryAppStage = primaryStage;
                  AnchorPane page = (AnchorPane) FXMLLoader.load(FxTableApplication.class.getResource("PieExample.fxml"));
                  final Scene scene = new Scene(page);
                  primaryAppStage.setTitle("No idea...");
              } catch (Exception e) {

          public static void main(String[] args) {
              System.out.println("To speed things up please run with -Xms16m -Xmx16m (" + args.toString() + ")");




            vadim Vadim Pakhnushev
            duke J. Duke
            1 Vote for this issue
            4 Start watching this issue