Author: rwhitcomb
Date: Tue Dec  2 00:00:34 2014
New Revision: 1642790

URL: http://svn.apache.org/r1642790
Log:
Change the code in ChartView.java "setValueMarkers" method to not create a new
list listener every time.  The listener is notifying the skin (basically) when
changes in the value markers list happen, so it only needs to be created once
and then assigned to the new list every time the list changes.  And it must
be removed from the old list at that time.  Change the logic to look like all
other such occurrences.

Basically, heap monitoring showed the large number of these listener objects
being created, which are unnecessary.

Modified:
    pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java

Modified: pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java?rev=1642790&r1=1642789&r2=1642790&view=diff
==============================================================================
--- pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java (original)
+++ pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java Tue Dec  2 
00:00:34 2014
@@ -421,6 +421,7 @@ public abstract class ChartView extends 
     private CategorySequence categorySequence = new CategorySequence();
 
     private ListHandler chartDataHandler = new ListHandler();
+    private ValueMarkersHandler valueMarkersHandler = new 
ValueMarkersHandler();
 
     private ChartViewListenerList chartViewListeners = new 
ChartViewListenerList();
     private ChartViewCategoryListenerList chartViewCategoryListeners = new 
ChartViewCategoryListenerList();
@@ -583,9 +584,17 @@ public abstract class ChartView extends 
     }
 
     public void setValueMarkers(List<ValueMarker> valueMarkers) {
-        this.valueMarkers = valueMarkers;
-        if (valueMarkers != null) {
-            valueMarkers.getListListeners().add(new ValueMarkersHandler());
+        List<ValueMarker> previousValueMarkers = this.valueMarkers;
+
+        if (previousValueMarkers != valueMarkers) {
+            if (previousValueMarkers != null) {
+                
previousValueMarkers.getListListeners().remove(valueMarkersHandler);
+            }
+
+            this.valueMarkers = valueMarkers;
+            if (valueMarkers != null) {
+                valueMarkers.getListListeners().add(valueMarkersHandler);
+            }
         }
     }
 


Reply via email to