I am using Jfreechart (jfreechart-1.0.13.jar) for the first time with struts1, java6, jboss4. I use this code to create the chart :
private JFreeChart getJfreeChart(int product, int msg) {
DefaultPieDataset dpd = new DefaultPieDataset();
dpd.setValue("product", product);
dpd.setValue("msg", msg);
JFreeChart chart = ChartFactory.createPieChart3D(null, dpd, true, false, false);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSectionPaint("product", new Color(51, 102, 153));
plot.setSectionPaint("msg", new Color(160, 218, 230));
plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} : {1}"));
return chart;
}
In my action, I do like this to display the chart:
response.setContentType("image/png");
ServletOutputStream outputStream = response.getOutputStream();
ChartUtilities.writeChartAsPNG(outputStream, chart, 900, 450);
outputStream.close();
In my jsp, I use <img src="MyAction.do" />
to display the chart
When I execute getJfreeChart, There I notice a memory leak . Is there an anomaly in my code ?
java.lang.OutOfMemoryError: PermGen space
at javax.swing.UIManager.initialize(Unknown Source)
at javax.swing.UIManager.maybeInitialize(Unknown Source)
at javax.swing.UIManager.getDefaults(Unknown Source)
at javax.swing.UIManager.getColor(Unknown Source)
at org.jfree.chart.JFreeChart.<clinit>(JFreeChart.java:261)
at org.jfree.chart.ChartFactory.createPieChart3D(ChartFactory.java:763)