简体   繁体   English

sun.font.TrueTypeFont内存泄漏?

[英]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. 我一直在使用堆转储分析一些Java软件,并且有350个sun.font.TrueTypeFont实例,在我已经采取的其他堆转储中有更多。 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. 应用程序代码只创建了5个Font实例,总共有24个实例,主要由WDesktopProperties和其他Java库类创建。

Is this number of TrueTypeFont instances typical for a fairly large desktop app? 对于相当大的桌面应用程序,这个TrueTypeFont实例的数量是否典型? If so then why? 如果是这样,为什么? The FontManager takes up almost 200kb of RAM! FontManager占用了近200kb的RAM!

Thanks, 谢谢,

Andy 安迪

Most likely, something is calling GraphicsEnvironment.getAllFonts() . 最有可能的是,有些东西正在调用GraphicsEnvironment.getAllFonts() A call to that will allocate a 1 point font in every installed typeface. 对它的调用将在每个已安装的字体中分配1磅字体。 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. 解析更多的工作,但另一种方法是使用GraphicsEnvironment.getAvailableFontFamilyNames(),因为它只返回名称而不实例化任何字体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM