OutOfMemoryError

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
FunkyELF
Posts: 11
Joined: Wed Nov 29, 2006 3:48 pm

OutOfMemoryError

Post by FunkyELF » Fri Jan 12, 2007 7:15 pm

Hello everyone.

I am having problems with an application I wrote using jfreechart.
I am opening up a file file and reading in 84 sets of data with 1600 data points each.
All of this data stays in memory in 84 DataFile objects which extend Vector<DataPoint> so I can do stuff like this...

Code: Select all

DataFile dataFile = new DataFile();
dataFile.add(new DataPoint(12.5,23.4));
A DataPoint is just an object which holds an X and Y value.

Also, my DataFile class has an XYSeries.

I realize that i am holding on to duplicate data here.

So, the program loads, reads in the file and there are no problems, everything fits into memory.
I hold all datafiles in a JList and when they are selected, they are rendered.

Here is my code for rendering...
This is a in a class that extends JPanel

Code: Select all

    public void createChart(){
        DataFile data = Global.currentDataFile;
        
        if(data == null)
            return;
        
        System.err.println("createChart() : " + data.getName());

        // remove the current plot
        this.removeAll();
        System.gc();

        XYSeries series = data.getSeries();
        
        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series);
        
        JFreeChart chart = ChartFactory.createXYLineChart(Global.currentDataFile.getName(), "Freq (Hz)", "Real", dataset, PlotOrientation.VERTICAL, true, true, false);
        chart.getXYPlot().setRangeZeroBaselinePaint(Color.MAGENTA);
        chart.getXYPlot().setRangeZeroBaselineVisible(true);
        chart.getXYPlot().getRangeAxis().setLowerMargin(.2);
        //chart.getXYPlot().setRangeZeroBaselineStroke(new BasicStroke(2));

        // do first with slope = -1, then with slope = +1, then exit the do loop.
        int slope = -1;
        do{
            for(int i = 0 ; i < data.getZeros(slope).size() ; i++){
                ZeroCrossing z = data.getZeros(slope).get(i);
                if(z.isActivated()){
                    //System.out.println(z);
                    XYTextAnnotation t1 = new XYTextAnnotation(String.format("%.2f",z.getZero()),z.getZero(),-1 * data.getAbsMax() - .4);
                    t1.setRotationAngle(3 * Math.PI / 2);            
        
                    // vertical line
                    XYLineAnnotation l1 = new XYLineAnnotation(z.getZero(),-1,z.getZero(),1,new BasicStroke(0.5f),Color.BLUE);

                    chart.getXYPlot().addAnnotation(t1);
        
                    chart.getXYPlot().addAnnotation(l1);
                }
            }
            slope *= -1;
        }while(slope != -1);
        chart.getXYPlot().getRangeAxis().setAutoRangeMinimumSize(3);
        chart.getXYPlot().getRangeAxis().centerRange(0);
        ChartPanel cp = new ChartPanel(chart);
        this.add(cp,BorderLayout.CENTER);
        this.updateUI();
        Global.botPane.setUp();
    }
Every time I render something, I call the following two methods...

Code: Select all

        this.removeAll();
        System.gc(); 
....which I would hope would clear up all of the references.

Going from chart to chart is real fast when it starts up, then it starts getting slow, then I start getting OutOfMemoryErrors.

Since all data is getting loaded up front and there are no changes to these DataFile Objects and the first 20 or so of them can be displayed without problem, I figured the problem is in my creation of the chart.
Like I said, all data is loaded up front...the only objects being created after the initial startup are these charts.

Any ideas?
The container of the chart is calling this.removeAll();...so would that destroy the chart properly?

Any help is appreciated.

Thanks,
~Eric

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Mon Jan 15, 2007 4:08 pm

It's pretty hard to diagnose the problem without seeing all the code (although even if I had all your code, I probably wouldn't have time to work through it).

One possibility to investigate for a memory leak is the line where you add the new ChartPanel to 'this' (presumably 'this' is a Swing container of some sort)...maybe the former ChartPanel is still referenced by the container, so the chart and dataset never get released for garbage collection.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

FunkyELF
Posts: 11
Joined: Wed Nov 29, 2006 3:48 pm

Post by FunkyELF » Mon Jan 15, 2007 8:41 pm

Well, I have since modified my DataFile class to extend XYSeries.
This obviously helped in that it probably uses about half as much memory as it used to.
Without any other changes I'm sure the memory leak is still there but I'm not running into problems.

Locked