java 永久代内存不足的原因
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5635255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PermGen Out of Memory reasons
提问by Raman
I constantly detect OOM in PermGen for my environment:
我不断地在 PermGen 中检测到我的环境中的 OOM:
- java 6
- jboss-4.2.3
- Not a big web-application
- 爪哇 6
- jboss-4.2.3
- 不是一个大型的网络应用程序
I know about String.intern() problem - but I don't have enough valuable usage of it. Increasing of MaxPermGen size didn't take a force (from 128 Mb to 256 Mb).
我知道 String.intern() 问题 - 但我没有足够的有价值的用法。MaxPermGen 大小的增加并没有太大影响(从 128 Mb 到 256 Mb)。
What other reasons could invoke OOM for PermGen? What scenario of investigation is the best in such situation (strategy, tools and etc.)?
还有哪些其他原因可以为 PermGen 调用 OOM?在这种情况下,哪种调查方案是最好的(策略、工具等)?
Thanks for any help
谢谢你的帮助
回答by Dead Programmer
- Put JDBC driver in common/lib (as tomcat documentation says) and not in WEB-INF/lib
- Don't put commons-logging into WEB-INF/lib since tomcat already bootstraps it
- 将 JDBC 驱动程序放在 common/lib 中(如 tomcat 文档所述)而不是 WEB-INF/lib
- 不要将 commons-logging 放入 WEB-INF/lib 中,因为 tomcat 已经引导它了
new class objects get placed into the PermGen and thus occupy an ever increasing amount of space. Regardless of how large you make the PermGen space, it will inevitably top out after enough deployments. What you need to do is take measures to flush the PermGen so that you can stabilize its size. There are two JVM flags which handle this cleaning:
新的类对象被放入永久代,因此占据越来越多的空间。无论您的 PermGen 空间有多大,经过足够的部署后,它都将不可避免地达到顶峰。您需要做的是采取措施冲洗 PermGen,以便您可以稳定其大小。有两个 JVM 标志可以处理这种清理:
-XX:+CMSPermGenSweepingEnabled
This setting includes the PermGen in a garbage collection run. By default, the PermGen space is never included in garbage collection (and thus grows without bounds).
此设置包括垃圾回收运行中的 PermGen。默认情况下,永久代空间永远不会包含在垃圾收集中(因此会无限增长)。
-XX:+CMSClassUnloadingEnabled
This setting tells the PermGen garbage collection sweep to take action on class objects. By default, class objects get an exemption, even when the PermGen space is being visited during a garabage collection.
此设置告诉 PermGen 垃圾收集清除对类对象采取行动。默认情况下,类对象获得豁免,即使在垃圾回收期间访问 PermGen 空间也是如此。
回答by Michael Borgwardt
You typically get this error when redeploying an application while having a classloader leak, because it means all your classes are loaded again while the old versions stay around.
在有类加载器泄漏的情况下重新部署应用程序时,您通常会遇到此错误,因为这意味着您的所有类都将再次加载,而旧版本仍然存在。
There are two solutions:
有两种解决方案:
- Restart the app server instead of redeploying the application - easy, but annoying
- Investigate and fix the leak using a profiler. Unfortunately, classloader leaks can be very hard to pinpoint.
- 重新启动应用程序服务器而不是重新部署应用程序 - 简单,但很烦人
- 使用分析器调查并修复泄漏。不幸的是,类加载器泄漏很难确定。