有什么办法可以“冲水”吗?内置字符串?
出于性能原因,我正在使用外部库,该库使用 String.intern() 。没关系,但是我在给定的运行中很多调用该库,所以我遇到了可怕的情况
java.lang.OutOfMemoryError:永久代空间
显然我可以使用 JVM 命令行 -XX:MaxPermSize
修饰符,但该解决方案的可扩展性不太好。相反,有没有办法定期(在两“批”库调用之间)“刷新”保留字符串池,即清空 String 类保存的静态字符串表?
I'm using an external library which uses String.intern() for performance reasons. That's fine, but I'm invoking that library a lot in a given run and so I run into the dreaded
java.lang.OutOfMemoryError: PermGen space
Obviously I can use the JVM command-line -XX:MaxPermSize
modifier, but that solution isn't very scalable. Instead, is there any way to periodically (between two "batches" of library calls) "flush" the interned string pool, i.e. empty the static table of strings held by the String class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,只需适当调整 Permgen 的大小即可。这与必须适当调整堆大小没有什么不同。别害怕!
No. Just size permgen appropriately. It's no different to having to size the heap appropriately. Don't be afraid!
进一步调查,我发现这篇文章,这似乎表明保留的字符串仍然被垃圾收集。我想这意味着我的问题是一个更深层次的问题 - 我使用的库必须仍然保留对这些字符串的活引用:(
Investigating further, I found this article, which seems to demonstrate that interned strings are still garbage collected. I guess that means that my problem here is a deeper one - the library I use must still hold a living reference to these strings :(