JFreechart & OutOfMemory

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
pang

JFreechart & OutOfMemory

Post by pang » Tue May 03, 2005 1:59 pm

:evil:
Hi, i'm developing an application using jfreechart. I load a txt file contains columns of integer
and i load it in freechart object. I use "add(x,y)" where x is a constant object representing a
specified value changing by time (and y is the column).

But if i have a file with n row and m columns i must create n*m objects, so with only 1MB file
my program crashes in OutOfMemory error.

How can i do?

(excuse me for my english, i'm italian :) )

Guest

Post by Guest » Tue May 03, 2005 4:21 pm

Though you have 1 MB data to be loaded, the idea is to load the data only in the view port and add more data as you scroll through.

Read this post for reference.

http://www.jfree.org/phpBB2/viewtopic.php?t=12682

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 » Thu May 05, 2005 12:12 am

I am surprised that a 1mb file would cause that trouble, but it is hard to guess what the problem might be as you didn't mention which class(es) you are using...some sample code to reproduce the problem would be useful.

Alternatively, try increasing the maximum heap size for your JVM (using -Xmx on the command line when you invoke 'java').
David Gilbert
JFreeChart Project Leader

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

pang

myCode

Post by pang » Fri May 06, 2005 9:52 am

Ok, that's my code that keeps a input file and stores data in XYSeries

timeStep = 1;
dataSet = new XYSeriesCollection();
int k = 0;
XYSeries[] series = null;
double x = 0;

while (!input.eof()) {

String s = input.readString();

if (!s.equals("")) {

k++;
String names = s;
StringTokenizer st = new StringTokenizer(names);

//first read, i'm creating series names
if(k==1)
{
series = new XYSeries[st.countTokens()];
//my class for showing progress (0% to 100%)
progress = new ProgressDialog("Plotting", series.length);

for (int i = 0; i < series.length; i++)
series = new XYSeries(st.nextToken(), true, false);

System.out.println("Created series "+series);
}

else
{
st = new StringTokenizer(s);
int j = 0;
while (j < series.length) {
double y = Double.parseDouble(st.nextToken());
series[j].add(x,y);
j++;
}

progress.setProgress(k);
x += timeStep;
}


} //s!=""

} //while read

for (int i = 0; i < series.length; i++)
dataSet.addSeries(series);

if(progress!=null)
progress.dispose();
input.close();

//end buildInput

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 » Fri May 06, 2005 4:43 pm

No obvious problems in there. Did you try increasing the maximum heap size for the JVM?
David Gilbert
JFreeChart Project Leader

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

Guest

Post by Guest » Tue May 10, 2005 8:51 am

I can try it.

I have seen that when i create more than 50000 series there is the problem.
The creation is fast, but when i want to show the result in a frame the painting time is long and if there are more than 50000 series, it crashes in OutOfMemory.

My solution was to decrease the precision of graph, jumping some lines of input file :) I think that for my scope should be reasonable.

Thank you for your support!

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 » Tue May 10, 2005 8:44 pm

Make sure you have tooltips and URLs disabled, those will use a lot of memory at drawing time. If you are displaying the chart in a ChartPanel, you may also need to disable the collection of chart entities:

Code: Select all

        chartPanel.getChartRenderingInfo().setEntityCollection(null);
David Gilbert
JFreeChart Project Leader

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

pang

I will try

Post by pang » Thu May 12, 2005 1:50 pm

I will try it, and in some days i'll send you a response.

Thank you. :lol:

Guest

Post by Guest » Mon May 23, 2005 8:13 pm

Dave Gilbert, only one word can define him: a GREAT! :lol:

The problem was resolved setting
chartPanel.getChartRenderingInfo().setEntityCollection(null);

as you suggest me in previous post.

Now JFreeChart is more more more fast, and i can draw charts more
complicated and detailed!!!

After rendering, if i want to redraw the window jFreeChart is very fast to redraw!!! OutOfMemory problem is died :wink: :wink:
When i tried your suggestion, i was surprised about result!!!

Thank you a lot, and good luck for future versions of this fantastic library for Java.

amihayb
Posts: 1
Joined: Thu Aug 30, 2007 1:48 pm

Heap when using org.jfree.chart.ChartPanel.paintComponent

Post by amihayb » Thu Aug 30, 2007 1:56 pm

david.gilbert wrote:Make sure you have tooltips and URLs disabled, those will use a lot of memory at drawing time. If you are displaying the chart in a ChartPanel, you may also need to disable the collection of chart entities:

Code: Select all

        chartPanel.getChartRenderingInfo().setEntityCollection(null);
Hi

Well, I have the same problem:
I have a SMALL data set (500 items) and only 1 chart that I repaint every 40 seconds.
After letting it run for an hour or so, the heap starts to raise (limit was irrelevant, since it throw the exception even with 1024MB Heap Limit) from the normal of my app (50MB) until OutOfMemory exception.
When I ran profiler I saw it ALWAYS happen in the org.jfree.chart.ChartPanel.paintComponent method, and it seems that DateTick is being created hundreds of thousands of times.
After that the GC cleans most of the heap, and the problem NEVER returns in this run.
After restarting my application, it is all over again.
BTW, version 1.0.6 improved something since with 1.0.2 it was 7 minutes after launching the application, and now it is after 30-60 minutes.

I saw many had the same problems but I didn't find any real cure.
It seems the while loop in DateAxis (line 1517) does the problems.
Any ideas?
Thanks
Ami

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 » Thu Aug 30, 2007 4:41 pm

Any chance you could supply a small self-contained demo that shows the memory leak? If JFreeChart is holding onto references that it shouldn't, then I'd like to track that down and fix it...but more often than not, reported memory leaks turn out to be in user code (up till now, anyway).
David Gilbert
JFreeChart Project Leader

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

fhaselbein
Posts: 6
Joined: Tue Oct 16, 2007 3:42 pm

Post by fhaselbein » Wed Oct 24, 2007 3:32 pm

Hi all,

I had a similar problem:
1 year of data = about 70000 datapoints (XYDataset), with 3 datasets there was an OutOfMemoryExc.
I fixed it by setting the EntityCollection in the ChartRenderingInfo to null, now it works with at least 10 datasets (although it takes nearly 1 minute to create the trend), I didn't test it with more:

Code: Select all

	JFreeChart chart = ChartFactory.createTimeSeriesChart(
	            null,  // title
	            null,  // x-axis label
	            null,  // y-axis label
	            null,  // data
	            false, // create legend?
	            false, // generate tooltips?
	            false  // generate URLs?
	        );
        //the datasets are added 


    	ChartRenderingInfo renderInfo = new ChartRenderingInfo(null);
    		BufferedImage image = chart.createBufferedImage(width, height, renderInfo);
...At least it helped at my side, maybe it helps you too...

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 » Wed Oct 24, 2007 10:17 pm

This is a slightly different problem, in that JFreeChart is precomputing the tooltips and hotspot areas for all 70,000 data items...so it is using up vast amounts of memory, rather than leaking it. By setting the ChartRenderingInfo argument to null, you disable the generation of the tooltips...which solves the memory usage problem.

The tooltip mechanism is poorly designed for charts with large datasets...hopefully I can fix that in the future.
David Gilbert
JFreeChart Project Leader

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

adesis
Posts: 1
Joined: Mon Feb 04, 2008 11:31 am

Post by adesis » Mon Feb 04, 2008 11:38 am

Hi.

We are making a chart with jFreeChart.

JFreeChart chart = new JFreeChart(
"BPM",
new Font("Verdana", Font.BOLD, 12),
plot,
true);

plot is load with two axis, y axis to value an x axis to dates.
We use

try{
//ChartUtilities.saveChartAsPNG(createFile(fileNameChart),chart,width,height);
ChartRenderingInfo renderInfo = new ChartRenderingInfo(null);
BufferedImage bi = chart.createBufferedImage(width,height,renderInfo);
// Create the .jpg
EncodeJpgFile(bi, fileNameChart);
}
catch(Exception e){
log.error ("[CHARTBUILDER] Error generateJfreeChartBPM - " + e.toString());
e.printStackTrace(System.out);
}

Because ChartUtilities.saveChartAsPNG(createFile(fileNameChart),chart,width,height);
qives out.ofMemoryError, but after several reloads, we have this error at chart.createBufferedImage(width,height,renderInfo);

Any ideas?
Thanks in advance.

Mike
Posts: 1
Joined: Thu May 05, 2011 7:44 pm
antibot: No, of course not.

Re: JFreechart & OutOfMemory

Post by Mike » Thu May 05, 2011 7:57 pm

I have a java application using jfreechart.
The application allows up to 10 series and each series will typically contain 24-48 datapoints.
There are checkboxes for several parameters and the application will re-plot any time the status of the checkbox changes.
I am using a chartPanel and tooltips.
The problem is that progressive use of the application requires more and more heap memory.
The problem is partially alleviated by using appropriate vm settings however I was wondering
a) what is going on and
b) is there a way to minimize the increase memory needed
I have tried turning off tooltips but this did not affect the memory usage.

Here is a sample of heap usage as a function of checkbox clicks.

1 Heap size: 16252928
2 Heap size: 28807168
3 Heap size: 28807168
4 Heap size: 28807168
5 Heap size: 43560960
6 Heap size: 43560960
7 Heap size: 43560960
8 Heap size: 43560960
9 Heap size: 43560960
10 Heap size: 79679488
11 Heap size: 79679488
12 Heap size: 79679488
after 80 clicks the heap size is up to around 256MB.

Locked