简体   繁体   English

为什么webappclassloader不是垃圾收集?

[英]why webappclassloader is not garbage collected ?

I have a web service developped by spring/hibernate, and when I do deployment and undeployment on Tomcat 7 many times, I get an outOfMemoryError PermGen Memory leak. 我有一个由spring / hibernate开发的Web服务,当我多次在Tomcat 7上进行部署和取消部署时,我得到一个outOfMemoryError PermGen内存泄漏。

By using java VisualVM, I noticed that the previous webappClassLoader are still kept in JVM, so they are not garbage collected. 通过使用java VisualVM,我注意到之前的webappClassLoader仍保留在JVM中,因此它们不会被垃圾回收。

What can be the reasons of this problem ? 这个问题可能是什么原因?

How can I detect which objects still have reference to the application class loader or any object loaded by it ? 如何检测哪些对象仍然引用了应用程序类加载器或由它加载的任何对象?

Thanks, 谢谢,

The short answer is that you have a memory leak. 简短的回答是你有内存泄漏。 From experience, this is most likely to be in your web application or a library it is using. 根据经验,这很可能是在您的Web应用程序或它正在使用的库中。 It is also possible, but unlikely, that you have found a memory leak in Tomcat. 在Tomcat中发现内存泄漏也是可能的,但不太可能。

The short version for tracking down the memory leak is: 用于跟踪内存泄漏的简短版本是:

  • Start Tomcat 启动Tomcat
  • Undeploy and redeploy the problematic application once 取消部署并重新部署有问题的应用程序一次
  • Use a profiler to examine the heap 使用分析器检查堆
  • Look for an instances of the WebappClassLoader 查找WebappClassLoader的实例
  • Find the one that is strongly held but has an attribute of started = false 找到一个强保持但属性为starts = false的那个
  • Trace the GC roots for that instance of the WebappClassLoader 跟踪WebappClassLoader的该实例的GC根
  • That will point to your memory leak 这将指向你的内存泄漏

Finding the root cause of the memory leak might be a little harder. 找到内存泄漏的根本原因可能会有点困难。

For a fuller explanation of how to track down this sort of memory leak and what might cause them see this presentation: http://people.apache.org/~markt/presentations/2010-08-05-Memory-Leaks-JavaOne-60mins.pdf 有关如何追踪此类内存泄漏以及可能导致它们的原因的更全面解释,请参阅此演示文稿: http//people.apache.org/~markt/presentations/2010-08-05-Memory-Leaks-JavaOne- 60mins.pdf

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

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