Memory keeps increasing as new IlvChart instances are created

Article ID: 2281
Last updated: 29 May, 2018
Article ID: 2281
Last updated: 29 May, 2018
Revision: 3
Views: 536
Posted: 11 Mar, 2011
by Dean J.
Updated: 29 May, 2018
by Gargani A.

Question

Why memory keeps increasing as new IlvChart instances are created and how to avoid it?

Answer

The continuous creation of multiple IlvChart instances in the same application may lead to increasing amounts of memory usage. This is due to a default IlvScalableFontManager instance that is included in IlvChart.

This problem can be avoided by explicitly disposing of the font manager of the chart when the chart is no longer used. To do so, call the dispose() method like this (in JViews 7.5 or later):

chart.dispose();

or (in JViews 6.5 or earlier):

chart.getFontManager().dispose();

Another case to take into account regarding the resources used by the IlvChart is where the chart is used in a Web application environment, on a servlet; there, the chart is not shown in a top window, instead it is added to a hidden window to make it valid and printable to a bitmap - which is the purpose of the servlet.

Upon disposal of the chart, when it is no longer used, the chart must be detached from the window, and the window disposed of itself. This is the code to properly dispose of a chart instance in a servlet.

IlvChart chart = ...;
// JViews 7.5 or later: Dispose of the chart.
chart.dispose();
// JViews 6.5 or earlier: Dispose the font manager.
chart.getFontManager().dispose();
java.awt.Container parent = chart.getParent();
parent.remove(chart);
java.awt.Component root = javax.swing.SwingUtilities.getRoot(parent);
if (root instanceof java.awt.Window)
((java.awt.Window)root).dispose();

Finally, if font scaling is not being used, you can call chart.getFontManager().dispose() immediately, and let the memory manager handles garbage collection.

Note: This issue has been resolved in JViews 8.8. It is not necessary to explicitly called dispose() on the chart or the fontManager when using JViews 8.8 or later.

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2281
Last updated: 29 May, 2018
Revision: 3
Views: 536
Posted: 11 Mar, 2011 by Dean J.
Updated: 29 May, 2018 by Gargani A.

Others in this category