From 3714ab9b50c3f6b02e7919276b471649ae2ce4d3 Mon Sep 17 00:00:00 2001 From: Lee Venable Date: Thu, 5 Sep 2013 09:49:28 -0500 Subject: [PATCH] Issue #2332 - fixed graph memory leaks Change-Id: I298df2996d5a5c12ca3216659691741fe97277f5 Former-commit-id: 4cb05eca7c2bd3714084e22a5e317de58b670bff [formerly d29663ddb88934d1160a21f5c55675923a4f50d1] [formerly fa972943ce28985089ff02993ae023b493b9530f] [formerly 4cb05eca7c2bd3714084e22a5e317de58b670bff [formerly d29663ddb88934d1160a21f5c55675923a4f50d1] [formerly fa972943ce28985089ff02993ae023b493b9530f] [formerly c7c8efe65f59a50bd88029015483422929dafcf1 [formerly fa972943ce28985089ff02993ae023b493b9530f [formerly ab943585c58005575f6497575a882e9a4054d38c]]]] Former-commit-id: c7c8efe65f59a50bd88029015483422929dafcf1 Former-commit-id: 56a010b487ca5d989f5d4022c2f2ac50889cbaff [formerly e86a5d86205f055196471eb0710d1b66b93c19c3] [formerly 95bce9603270a38ab5e87c55f922e548ed28a396 [formerly 1bc4fd1099ea147b2b58c3fb884c79490acf9de0]] Former-commit-id: c62048007bbe1d904c5bac67e0412ef030b6a6a9 [formerly 9071f715fc0d1257dfb68226e254fba42c955151] Former-commit-id: 5facc63c174b0b4b0fb21e27f555e4a70bbed7ce --- .../timeseries/TimeSeriesDisplayCanvas.java | 95 ++++++++++--------- .../graph/TimeSeriesGraphCanvas.java | 49 +++++++--- 2 files changed, 83 insertions(+), 61 deletions(-) diff --git a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TimeSeriesDisplayCanvas.java b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TimeSeriesDisplayCanvas.java index 33f9fd079f..a556addad8 100644 --- a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TimeSeriesDisplayCanvas.java +++ b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TimeSeriesDisplayCanvas.java @@ -138,7 +138,8 @@ import com.raytheon.viz.hydrocommon.util.DbUtils; * 16 Jan 2013 15695 wkwock Fix popup menu * 24 Apr 2013 1921 mpduff Fix zoom reset to only reset the "active" graph * 06 May 2013 1976 mpduff Refactored Hydro time series data access. - * 29 May 2013 2016 mpduff Fix TS Toggle Traces. + * 29 May 2013 2016 mpduff Fix TS Toggle Traces. + * 05 Sep 2013 #2332 lvenable Fixed memory leaks. * @author lvenable * @version 1.0 * @@ -165,7 +166,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements /** * No Data Available string. */ - private static final String NO_DATA_AVAILABLE = "NO DATA AVAILABLE"; + private final String NO_DATA_AVAILABLE = "NO DATA AVAILABLE"; /** Location ID */ private String lid = null; @@ -234,17 +235,17 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements /** * List of regions for a single trace */ - private final ArrayList regionList = new ArrayList(); + private final List regionList = new ArrayList(); /** * List of Region Lists */ - private final ArrayList> listRegionList = new ArrayList>(); + private final List> listRegionList = new ArrayList>(); /** * List of regions for points for each trace */ - private final ArrayList> pointList = new ArrayList>(); + private final List> pointList = new ArrayList>(); /** * Is a point selected? @@ -328,11 +329,6 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements /** Graph display Date Format MM/dd/yy HH 'z' */ public SimpleDateFormat graphFormat; - /** - * List of graph traces that are available. - */ - private ArrayList validGraph; - /** * Show Latest Forecast flag. */ @@ -483,6 +479,8 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements if ((canvasFont != null) && (canvasFont.isDisposed() == false)) { canvasFont.dispose(); } + + disposeRegions(); } }); @@ -1143,7 +1141,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } if (points != null) { - ArrayList pointList = new ArrayList(); + List pointList = new ArrayList(); /* Delete the specified point */ if ((deleteList.size() > 0) && (i == selectedTraceId)) { for (int j = 0; j < points.length; j++) { @@ -1623,7 +1621,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } else if (dialog.isSelectMove() && traceSelected && !pointSelected) { // This catches the move event before point is selected if (!precipPE) { - ArrayList prl = pointList.get(selectedTraceId); + List prl = pointList.get(selectedTraceId); for (int i = 0; i < prl.size(); i++) { if (prl.get(i).contains(e.x, e.y)) { setCursor(northSouthCursor); @@ -1634,7 +1632,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } } } else { - ArrayList ppl = precipPointList.get(selectedTraceId); + List ppl = precipPointList.get(selectedTraceId); for (int i = 0; i < ppl.size(); i++) { if (ppl.get(i).contains(e.x, e.y)) { setCursor(northSouthCursor); @@ -1654,8 +1652,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements redraw(); } else { if (precipPE) { - ArrayList ppl = precipPointList - .get(selectedTraceId); + List ppl = precipPointList.get(selectedTraceId); for (int i = 0; i < ppl.size(); i++) { if (ppl.get(i).contains(e.x, e.y)) { setCursor(northSouthCursor); @@ -1666,7 +1663,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } } } else { - ArrayList prl = pointList.get(selectedTraceId); + List prl = pointList.get(selectedTraceId); for (int i = 0; i < prl.size(); i++) { if (prl.get(i).contains(e.x, e.y)) { setCursor(handCursor); @@ -1687,8 +1684,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements redraw(); } else { if (precipPE) { - ArrayList ppl = precipPointList - .get(selectedTraceId); + List ppl = precipPointList.get(selectedTraceId); for (int i = 0; i < ppl.size(); i++) { if (ppl.get(i).contains(e.x, e.y)) { setCursor(handCursor); @@ -1699,7 +1695,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } } } else { - ArrayList prl = pointList.get(selectedTraceId); + List prl = pointList.get(selectedTraceId); for (int i = 0; i < prl.size(); i++) { if (prl.get(i).contains(e.x, e.y)) { setCursor(handCursor); @@ -1898,7 +1894,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } else if (traceSelected && dialog.isSelectMove()) { // loop to see if a dot is selected if (precipPE) { - ArrayList prl = precipPointList.get(selectedTraceId); + List prl = precipPointList.get(selectedTraceId); for (int i = 0; i < prl.size(); i++) { if (prl.get(i).contains(e.x, e.y)) { setCursor(northSouthCursor); @@ -1910,7 +1906,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } } } else { - ArrayList prl = pointList.get(selectedTraceId); + List prl = pointList.get(selectedTraceId); for (int i = 0; i < prl.size(); i++) { if (prl.get(i).contains(e.x, e.y)) { setCursor(northSouthCursor); @@ -1924,7 +1920,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } } else if (traceSelected && dialog.isDelete()) { if (precipPE) { - ArrayList ppl = precipPointList.get(selectedTraceId); + List ppl = precipPointList.get(selectedTraceId); for (int i = 0; i < ppl.size(); i++) { if (ppl.get(i).contains(e.x, e.y)) { deleteIndex = i; @@ -1933,7 +1929,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } } } else { - ArrayList prl = pointList.get(selectedTraceId); + List prl = pointList.get(selectedTraceId); for (int i = 0; i < prl.size(); i++) { if (prl.get(i).contains(e.x, e.y)) { deleteIndex = i; @@ -1956,7 +1952,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } } else if (traceSelected && dialog.isSetMissing()) { if (precipPE) { - ArrayList ppl = precipPointList.get(selectedTraceId); + List ppl = precipPointList.get(selectedTraceId); for (int i = 0; i < ppl.size(); i++) { if (ppl.get(i).contains(e.x, e.y)) { setMissingIndex = i; @@ -1965,7 +1961,7 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } } } else { - ArrayList prl = pointList.get(selectedTraceId); + List prl = pointList.get(selectedTraceId); for (int i = 0; i < prl.size(); i++) { if (prl.get(i).contains(e.x, e.y)) { setMissingIndex = i; @@ -2176,29 +2172,9 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements */ private void makeRegions(List traceList) { if (createRegions == true) { + /* Dispose of the previous regions */ - for (Region r : regionList) { - if (r.isDisposed() == false) { - r.dispose(); - } - } - for (ArrayList al : pointList) { - for (Region r : al) { - if (r.isDisposed() == false) { - r.dispose(); - } - } - } - for (ArrayList al : listRegionList) { - for (Region r : al) { - if (r.isDisposed() == false) { - r.dispose(); - } - } - } - regionList.clear(); - pointList.clear(); - listRegionList.clear(); + disposeRegions(); int dy = 15; @@ -2278,6 +2254,31 @@ public class TimeSeriesDisplayCanvas extends TimeSeriesGraphCanvas implements } } + private void disposeRegions() { + for (Region r : regionList) { + if (r.isDisposed() == false) { + r.dispose(); + } + } + for (List al : pointList) { + for (Region r : al) { + if (r.isDisposed() == false) { + r.dispose(); + } + } + } + for (List al : listRegionList) { + for (Region r : al) { + if (r.isDisposed() == false) { + r.dispose(); + } + } + } + regionList.clear(); + pointList.clear(); + listRegionList.clear(); + } + /** * Set the point array to be drawn. * diff --git a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/graph/TimeSeriesGraphCanvas.java b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/graph/TimeSeriesGraphCanvas.java index 86ae6e1126..860f762da3 100644 --- a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/graph/TimeSeriesGraphCanvas.java +++ b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/graph/TimeSeriesGraphCanvas.java @@ -24,9 +24,12 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.List; import java.util.TimeZone; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Font; @@ -54,18 +57,19 @@ import com.raytheon.viz.hydrocommon.HydroConstants; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Sep 12, 2008 1519 mpduff Initial creation - * Jan 26, 2011 5557 bkowal Finished the implementation of - * "Reverse Video" printing. - * Feb 03, 2011 8085 mpduff Modified the trace line to circle - * around the point. - * Apr 18, 2011 8963 jpiatt Removed Left Scale call to scale manager. - * July 12 2011 9709 djingtao draw right Y axis for showPP is true. add new - * function adjust_pcymax() - * Aug. 10, 2011 10457 djingtao allow the red rubberband box to be drawn for setMissing in Edit - * Jul. 24, 2012 15195 mpduff Fix x axis scales. - * 06 Nov 2012 15399 wkwock Fix refine the plot algorithm and sampling algorithm - * May 06, 2013 1976 mpduff Code cleanup + * Sep 12, 2008 1519 mpduff Initial creation + * Jan 26, 2011 5557 bkowal Finished the implementation of + * "Reverse Video" printing. + * Feb 03, 2011 8085 mpduff Modified the trace line to circle + * around the point. + * Apr 18, 2011 8963 jpiatt Removed Left Scale call to scale manager. + * July 12 2011 9709 djingtao draw right Y axis for showPP is true. add new + * function adjust_pcymax() + * Aug 10, 2011 10457 djingtao allow the red rubberband box to be drawn for setMissing in Edit + * Jul 24, 2012 15195 mpduff Fix x axis scales. + * 06 Nov 2012 15399 wkwock Fix refine the plot algorithm and sampling algorithm + * May 06, 2013 1976 mpduff Code cleanup + * 05Sep2013 #2332 lvenable Fixed memory leaks. * * * @author mpduff @@ -173,9 +177,9 @@ public class TimeSeriesGraphCanvas extends Canvas { /* Flag for selection of 1hr PC as PP */ protected boolean showPP = false; - protected ArrayList precipRegions = new ArrayList(); + protected final List precipRegions = new ArrayList(); - protected ArrayList> precipPointList = new ArrayList>(); + protected final List> precipPointList = new ArrayList>(); protected int currentX; @@ -222,6 +226,23 @@ public class TimeSeriesGraphCanvas extends Canvas { public TimeSeriesGraphCanvas(Composite parent, int style) { super(parent, style); parentComp = parent; + init(); + } + + /** + * Initialize method. + */ + private void init() { + this.addDisposeListener(new DisposeListener() { + + @Override + public void widgetDisposed(DisposeEvent e) { + if (currentTraceColor != null + && currentTraceColor.isDisposed() == false) { + currentTraceColor.dispose(); + } + } + }); } /**