http://www.jfree.org/phpBB2/viewtopic.php?t=20945
I have files with a bunch of datasets (average is about 120 data sets with 1,600 datapoints each).
Every time I show a new data set, I create a new chart.
I could watch the memory usage go up as I go through the available charts. It would start at around 36 MB and go up from there, about a megabyte every 4 charts.
I solved this problem and now the memory hovers around 36 MB and going from chart to chart the memory will go up or down so I'm pretty sure I have the leak solved.
This is how I solved it. I commented the part the solves the problem
Code: Select all
this.removeAll();
// This is what solves the problem. Comment out these two lines and there will be memory leaks.
if(chart != null)
chart.getXYPlot().setDataset(0,null);
chart = ChartFactory.createXYLineChart(Global.currentDataFile.getName(), "Freq (Hz)", "Real", dataset, PlotOrientation.VERTICAL, true, true, false);
Without it, there will be memory leaks.
I have tried to only create the chart once in the constructor and change out the datasets by changing
Code: Select all
if(chart != null)
chart.getXYPlot().setDataset(0,null);
Code: Select all
if(chart != null)
chart.getXYPlot().setDataset(0,dataset);
Code: Select all
if(chart != null){
chart.getXYPlot().setDataset(0,null);
chart.getXYPlot().setDataset(0,dataset);
}
What should I be doing?
If I should be creating a new chart every time, why do I need to call chart.getXYPlot().setDataset(0,null); to not get any memory leaks. Is there a way to create a new chart every time and not get memory leaks without explicitly calling that? Shouldn't the this.removeAll(); fix everything?
If I should be re-using the same chart and just switching out the datasets, what am I doing wrong?
Thanks for the help in advance.
~Eric