简体   繁体   English

Java类(PermGen)内存泄漏(Web应用程序) - 通用解决方案?

[英]Java Class (PermGen) Memory Leak (Web Applications) - Generic Solution?

I have a perm gen memory leak, that I know. 我知道,我有一个perm gen内存泄漏。 Profiling using jvisualvm shows that when doing hot deployment (eg stop and start an application without killing the JVM, in tomcat, WebSphere, WebLogic etc) - the PermGen space is constantly increasing. 使用jvisualvm进行性能分析表明,在进行热部署时(例如,在不杀死JVM的情况下停止和启动应用程序,在tomcat,WebSphere,WebLogic等中) - PermGen空间不断增加。

After reading, using jhat, and other advanced tools I realized that I probably have a reference to the WebAppClassLoader from a class somewhere in its parent class loaders. 在阅读之后,使用jhat和其他高级工具,我意识到我可能在其父类加载器的某个类中引用了WebAppClassLoader

I couldn't pin it down even though I did some massive JavaScript based queries on jhat 即使我在jhat上做了一些基于JavaScript的大量查询,我也无法确定它

Isn't there a simple utility that finds out who is responsible for you class loader to not be garbage collected (thus allowing garbage collection of classes loaded by it)? 是不是有一个简单的实用程序可以找出谁负责你的类加载器不被垃圾收集(从而允许垃圾收集由它加载的类)?

I tried JProfiler, jvisualvm, jhat, and a lot of Google 我试过JProfiler,jvisualvm,jhat和很多Google

to all the LMGTFY friends - I've spent about a day and a half reading forums with step by steps instructions, no luck. 所有LMGTFY的朋友 - 我花了大约一天半的阅读论坛一步一步的说明,没有运气。 I'm looking for a utility or code that outputs: 我正在寻找输出的实用程序或代码:

Object X of class Y is the sole GC root that keeps your classes from being removed. Y类的对象X是唯一的GC根,它可以防止您的类被删除。

There is an unsatisfiying but easy solution: Don't hotdeploy in production environments. 有一个不令人满意但很容易的解决方案:不要在生产环境中进行热部署。 You could setup a cluster of two servlet containers and them update one at a time with a restart. 您可以设置一个包含两个servlet容器的集群,并在重新启动时一次更新一个。

The realities of frequent redeployments... Best you can do is increase the size of perm gen using -XX:MaxPermSize=256m. 频繁重新部署的现实......你能做的最好是使用-XX:MaxPermSize = 256m来增加perm gen的大小。 This may buy you some redeployments more per jvm restart. 这可能会为每个jvm重启更多地重新部署。 Or read on at http://my.opera.com/karmazilla/blog/2007/03/15/permgen-strikes-back 或者阅读http://my.opera.com/karmazilla/blog/2007/03/15/permgen-strikes-back

Beware that if the classloaders can't be gc-ed at all, fiddling with the jvm won't help at all. 请注意,如果类加载器根本不能被gc-ed,摆弄jvm将无济于事。 You'd better forget about frequent deployments, especially in production, for dev it's handy, nevertheless. 你最好忘记频繁的部署,特别是在生产中,尽管它很方便。

I used the method from this site and it helped. 我使用了这个网站的方法,但它有所帮助。 http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/ http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/

Few pointers here as well, http://minmaxmim.blogspot.com/2010/01/javalangoutofmemoryerror-java-heap.html 这里也很少指点, http://minmaxmim.blogspot.com/2010/01/javalangoutofmemoryerror-java-heap.html

also check the javalangoutofmemoryerror-permgen-space article. 还要查看javalangoutofmemoryerror-permgen-space文章。

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

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