Memory leak in org.jfree.text.TextUtilities

A discussion forum for the JCommon class library.
Post Reply
rasto1968
Posts: 3
Joined: Thu Sep 29, 2005 10:52 am

Memory leak in org.jfree.text.TextUtilities

Post by rasto1968 » 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

david.gilbert
JFreeChart Project Leader
Posts: 11680
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Sep 29, 2005 5:14 pm

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?
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited

rasto1968
Posts: 3
Joined: Thu Sep 29, 2005 10:52 am

Post by rasto1968 » Thu Sep 29, 2005 5:20 pm

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

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Sun Oct 02, 2005 11:25 am

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

rasto1968
Posts: 3
Joined: Thu Sep 29, 2005 10:52 am

Post by rasto1968 » Mon Oct 03, 2005 9:08 am

Sounds good, thanks :)

Rob

Post Reply