Page 1 of 1

Memory leak in org.jfree.text.TextUtilities

Posted: Thu Sep 29, 2005 4:51 pm
by rasto1968
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

Posted: Thu Sep 29, 2005 5:14 pm
by david.gilbert
Presumably this memory leak is happening in JDK code? Is there a bug report at Sun, and do you know what versions of the JDK are affected?

Posted: Thu Sep 29, 2005 5:20 pm
by rasto1968
I guess you could say it is in the JDK. The problem is, the code trace disappears into a sun. package, so there is no way of knowing what is going on in there. I'm not sure that I can describe the problem in sufficient detail to be able to file it at Sun, I certainly wouldn't be able to produce a simple test case.

Having said this, the bug that this is a workaround for appears to have been fixed in JDK 1.2, so would it not be better to default the workaround to 'off' in JCommon ?

I'm using JDK 1.5.

Edit: I did search around the JDK bug parade looking for any mention of this type of leak - but I couldn't see any obvious candidates.

Regards
Rob Stone

Posted: Sun Oct 02, 2005 11:25 am
by Taqua
Hi,

I've modified the TextUtilities classes to look at the JDK version before initializing the flags. The flags are now also configurable using the '/jcommon.properties' file.

Regards,
Thomas

Posted: Mon Oct 03, 2005 9:08 am
by rasto1968
Sounds good, thanks :)

Rob