Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sun.font.TrueTypeFont Memory Leak?

I've been profiling some Java software using heap dumps and there is 350 instances of sun.font.TrueTypeFont, in other heap dumps I have taken there have been more. There is only 5 instances of Font created by the app code, and 24 instances in all, mostly created by WDesktopProperties and other Java library classes.

Is this number of TrueTypeFont instances typical for a fairly large desktop app? If so then why? The FontManager takes up almost 200kb of RAM!

Thanks,

Andy


1 Answers

Most likely, something is calling GraphicsEnvironment.getAllFonts(). A call to that will allocate a 1 point font in every installed typeface. The actual memory consumption will depend on the number of fonts available, but it won't grow as they're only allocated once. It's more work to parse, but an alternative is to use GraphicsEnvironment.getAvailableFontFamilyNames() as that just returns the name without instantiating any fonts.

like image 96
Devon_C_Miller Avatar answered Dec 01 '25 12:12

Devon_C_Miller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!