changeset 6459:685651bc38c2

RT-36151 Custom XYChart Memory-Leak Reviewed by: jgiles
author Martin Sladecek <martin.sladecek@oracle.com>
date Tue, 11 Mar 2014 16:15:55 +0100
parents a4ee872a75bb
children d550116b8d71
files modules/controls/src/main/java/javafx/scene/chart/AreaChart.java modules/controls/src/main/java/javafx/scene/chart/BarChart.java modules/controls/src/main/java/javafx/scene/chart/LineChart.java modules/controls/src/main/java/javafx/scene/chart/XYChart.java
diffstat 4 files changed, 4 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/chart/AreaChart.java	Tue Mar 11 16:14:08 2014 +0100
+++ b/modules/controls/src/main/java/javafx/scene/chart/AreaChart.java	Tue Mar 11 16:15:55 2014 +0100
@@ -395,7 +395,6 @@
     }
     private void updateDefaultColorIndex(final Series<X,Y> series) {
         int clearIndex = seriesColorMap.get(series);
-        colorBits.clear(clearIndex);
         Path seriesLine = (Path)((Group)series.getNode()).getChildren().get(1);
         Path fillPath = (Path)((Group)series.getNode()).getChildren().get(0);
         if (seriesLine != null) {
@@ -404,14 +403,12 @@
         if (fillPath != null) {
             fillPath.getStyleClass().remove(DEFAULT_COLOR+clearIndex);
         }
-        colorBits.clear(clearIndex);
         for (int j=0; j < series.getData().size(); j++) {
             final Node node = series.getData().get(j).getNode();
             if(node!=null) {
                 node.getStyleClass().remove(DEFAULT_COLOR+clearIndex);
             }
         }
-        seriesColorMap.remove(series);
     }
     @Override protected  void seriesRemoved(final Series<X,Y> series) {
         updateDefaultColorIndex(series);
--- a/modules/controls/src/main/java/javafx/scene/chart/BarChart.java	Tue Mar 11 16:14:08 2014 +0100
+++ b/modules/controls/src/main/java/javafx/scene/chart/BarChart.java	Tue Mar 11 16:15:55 2014 +0100
@@ -543,15 +543,12 @@
      
     private void updateDefaultColorIndex(final Series<X,Y> series) {
         int clearIndex = seriesColorMap.get(series);
-        colorBits.clear(clearIndex);
         for (Data<X,Y> d : series.getData()) {
             final Node bar = d.getNode();
             if (bar != null) {
                 bar.getStyleClass().remove(DEFAULT_COLOR+clearIndex);
-                colorBits.clear(clearIndex);
             }
         }
-        seriesColorMap.remove(series);
     }
 
     private Node createBar(Series series, int seriesIndex, final Data item, int itemIndex) {
--- a/modules/controls/src/main/java/javafx/scene/chart/LineChart.java	Tue Mar 11 16:14:08 2014 +0100
+++ b/modules/controls/src/main/java/javafx/scene/chart/LineChart.java	Tue Mar 11 16:15:55 2014 +0100
@@ -396,7 +396,6 @@
     }
     private void updateDefaultColorIndex(final Series<X,Y> series) {
         int clearIndex = seriesColorMap.get(series);
-        colorBits.clear(clearIndex);
         series.getNode().getStyleClass().remove(DEFAULT_COLOR+clearIndex);
         for (int j=0; j < series.getData().size(); j++) {
             final Node node = series.getData().get(j).getNode();
@@ -404,7 +403,6 @@
                 node.getStyleClass().remove(DEFAULT_COLOR+clearIndex);
             }
         }
-        seriesColorMap.remove(series);
     }
 
     @Override protected  void seriesRemoved(final Series<X,Y> series) {
--- a/modules/controls/src/main/java/javafx/scene/chart/XYChart.java	Tue Mar 11 16:14:08 2014 +0100
+++ b/modules/controls/src/main/java/javafx/scene/chart/XYChart.java	Tue Mar 11 16:15:55 2014 +0100
@@ -88,9 +88,9 @@
     // -------------- PRIVATE FIELDS -----------------------------------------------------------------------------------
 
     // to indicate which colors are being used for the series
-    BitSet colorBits = new BitSet(8);
+    private final BitSet colorBits = new BitSet(8);
     static String DEFAULT_COLOR = "default-color";
-    Map<Series, Integer> seriesColorMap = new HashMap<Series, Integer>();
+    final Map<Series, Integer> seriesColorMap = new HashMap<Series, Integer>();
     private boolean rangeValid = false;
     private final Line verticalZeroLine = new Line();
     private final Line horizontalZeroLine = new Line();
@@ -115,6 +115,8 @@
                     series.setToRemove = true;
                     series.setChart(null);
                     seriesRemoved(series);
+                    int idx = seriesColorMap.remove(series);
+                    colorBits.clear(idx);
 //                    seriesDefaultColorIndex --;
                 }
                 for(int i=c.getFrom(); i<c.getTo() && !c.wasPermutated(); i++) {