I am using JFreeChart to generate jpeg images in a servlet for a web application. The charts update once every minute. The code seems to work fine on Solaris, Linux and Windows, but there is a memory leak on Mac OSX - after some time the JVM runs out of memory and crashes. Has anyone else experienced this problem?
The chart type is an XYPlot, created with the following code
HorizontalDateAxis xAxis = new HorizontalDateAxis();
xAxis.setCrosshairVisible( false );
xAxis.setVerticalTickLabels( false );
SimpleDateFormat format = xAxis.getTickLabelFormatter();
format.applyPattern( "HH:mm" );
NumberAxis yAxis = new VerticalNumberAxis( yAxisLabel );
yAxis.setCrosshairVisible( false );
yAxis.setLabelInsets( new java.awt.Insets(0,0,0,20) );
double margin = m_yMargin * m_currYMax;
yAxis.setAxisRange( -margin, m_currYMax + margin );
XYPlot plot = new XYPlot( xAxis, yAxis );
plot.setXYItemRenderer( new StandardXYItemRenderer(StandardXYItemRenderer.LINES) );
chart = new JFreeChart( this, plot, title, new Font("SansSerif",Font.PLAIN,12), false );
chart.setAntiAlias(false);
Each time web page updates, the chart is redrawn (the dataset updates automatically) by caling the following code (Note the auto range feature for the axes was causing problems, so we manually set the axis ranges and we dump the output to a bytearray before sending it to the browser because we found writeChartAsJPEG crashed the JVM if the browser closed the socket connection mid-stream)
XYPlot plot = (XYPlot)m_chart.getPlot();
HorizontalDateAxis xAxis = (HorizontalDateAxis)plot.getDomainAxis();
Number minValue = getXValue( 0, 0 );
double min = minValue.longValue();
xAxis.setMinimumAxisValue( min );
Number maxValue = getXValue( 0, getItemCount(0)-1 );
double max = maxValue.longValue();
if ( max - min < 660000 ) // 11 minute minimum X axis size, 10 ticks
{
xAxis.setMaximumAxisValue( min + 660000 );
}
else
{
xAxis.setMaximumAxisValue( max );
}
NumberAxis yAxis = (NumberAxis)plot.getRangeAxis();
double trueMax = getMaxYValue( 0 );
if ( m_yMax > trueMax )
trueMax = m_yMax;
if ( trueMax <= 10.0 )
trueMax = 10.0;
if ( trueMax != m_currYMax )
{
m_currYMax = trueMax;
double margin = m_yMargin * m_currYMax;
yAxis.setAxisRange( -margin, m_currYMax + margin );
}
ByteArrayOutputStream stage = new ByteArrayOutputStream();
ChartUtilities.writeChartAsJPEG( stage, m_chart, m_width, m_height );
stream.write( stage.toByteArray() );
Thanks
Memory leak with Mac OSX
Re: Memory leak with Mac OSX
Hi Neal,
I don't have an answer...but please let me know if you find out anything.
Regards,
DG.
I don't have an answer...but please let me know if you find out anything.
Regards,
DG.
Re: Memory leak with Mac OSX
I'm having a problem with a memory leak in my applet running under Internet Explorer 6.0 under Windows2000. If I run the applet under JBuilder 7.0, however, no memory leak occurs. Leaking continues until the system runs out of memory and I have to kill the applet.
I'm using jfreechart-0.9.3.jar.
I'm using jfreechart-0.9.3.jar.
Re: Memory leak with Mac OSX
Correction, I was having the memory leak with jfreechart-0.9.2.jar. Version 0.9.3 seems to work fine.