From 1b8abcf1ce0469e8ed7bb9c7c883e3f61ca080e6 Mon Sep 17 00:00:00 2001 From: miettinen Date: Tue, 15 Jan 2013 13:05:25 +0000 Subject: [PATCH] Small memory leak fixed in redrawing the trend view (refs #3797). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26611 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../modelica/data/SimulationResult.java | 7 +++++++ .../simantics/sysdyn/ui/trend/TrendView.java | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java b/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java index 295dda54..cdfc3aca 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java +++ b/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java @@ -453,6 +453,13 @@ public class SimulationResult { if (names.contains(variable)) { double[] resArray = resultFileReader.readData(variable, 0, allTimes.length, skip); ds = new DataSet(variable, allTimes, resArray); + for (DataSet tempds : variables){ + if (tempds.name.equals(variable)) + // We should never need to go there unless some change in + // the logic of reading variables are made. + // Also helps in seeking memory leaks. + return; + } variables.add(ds); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java index 88b0314f..e730e1fb 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java @@ -39,13 +39,14 @@ import org.simantics.sysdyn.ui.viewUtils.SysdynDatasetSelectionListener; * Trend view that shows all active simulation results for selected variables. * * @author Teemu Lempinen + * @author Tuomas Miettinen * */ public class TrendView extends ViewPart { private Frame frame; public static ChartPanel panel; - private SysdynDatasets sysdynDatasets = new SysdynDatasets(); + private final SysdynDatasets sysdynDatasets = new SysdynDatasets(); private SysdynDatasetSelectionListener sysdynDatasetSelectionListener; public static JFreeChart defaultchart; private Composite composite; @@ -191,10 +192,20 @@ public class TrendView extends ViewPart { @Override public void run() { - frame.removeAll(); + // Do not just simply frame.removeAll(); + // Instead, use and reuse only the first component of the frame. if(jFreeChart != null) { - panel = new ChartPanel(jFreeChart, false, true, true, true, true); - frame.add(panel); + if (panel == null){ + panel = new ChartPanel(jFreeChart, false, true, true, true, true); + frame.add(panel); + } else { + panel.setChart(jFreeChart); + if ( frame.getComponent(0) instanceof ChartPanel ){ + ChartPanel tempPanel = (ChartPanel)frame.getComponent(0); + tempPanel.setChart(jFreeChart); + panel = tempPanel; + } + } } frame.repaint(); frame.validate(); -- 2.47.1