Memory leak in org.jfree.text.TextUtilities
Posted: Thu Sep 29, 2005 4:51 pm
Caused by the 'useDrawRotatedStringWorkaround' fix.
A bit of background first. I have a servlet based real-time chart package that uses JFreeChart. Recently I have noticed that it has been leaking memory, so after doing a lot of profiling I found that the leaks appeared to be instances of AffineTransform and FontRenderContext. The allocation traces for these showed them to be created as a result of the following code in TextUtilities:
if (useDrawRotatedStringWorkaround) {
// workaround for JDC bug ID 4312117 and others...
final TextLayout tl = new TextLayout(
text, g2.getFont(), g2.getFontRenderContext()
);
tl.draw(g2, textX, textY);
}
else {
// replaces this code...
g2.drawString(text, textX, textY);
}
Edit: To make it a bit clearer, the leak was caused by the new TextLayout call.
Disabling the workaround cured the memory leak. Is this fix still relevant ? If not, maybe it would be better to default the fix to off ?
Regards
Rob Stone
A bit of background first. I have a servlet based real-time chart package that uses JFreeChart. Recently I have noticed that it has been leaking memory, so after doing a lot of profiling I found that the leaks appeared to be instances of AffineTransform and FontRenderContext. The allocation traces for these showed them to be created as a result of the following code in TextUtilities:
if (useDrawRotatedStringWorkaround) {
// workaround for JDC bug ID 4312117 and others...
final TextLayout tl = new TextLayout(
text, g2.getFont(), g2.getFontRenderContext()
);
tl.draw(g2, textX, textY);
}
else {
// replaces this code...
g2.drawString(text, textX, textY);
}
Edit: To make it a bit clearer, the leak was caused by the new TextLayout call.
Disabling the workaround cured the memory leak. Is this fix still relevant ? If not, maybe it would be better to default the fix to off ?
Regards
Rob Stone