开发者

Tomcat WebappClassloader not garbage collected

开发者 https://www.devze.com 2023-03-26 08:22 出处:网络
I\'m trying to track down a memory leak in my web application which is causing the PermGen space to fill up and throw OutOfMemoryError: PermGen size after a couple of reloads. Now I know that I can ju

I'm trying to track down a memory leak in my web application which is causing the PermGen space to fill up and throw OutOfMemoryError: PermGen size after a couple of reloads. Now I know that I can just stop/start the whole Tomcat instance, but I'm trying to track down the cause of the memory leak.

I've read this article http://java.dzone.com/artic开发者_开发百科les/memory-leak-protection-tomcat which indicates that I must make sure that after stopping my application there should be no outstanding references to the WebappClassLoader, which will prevent it from being garbage-collected. Using YourKit and Memory Analyzer I found several cases where that was happening in 3rd party libs and fixed them.

I'm now at the point where both tools report that there are no 'Paths from GC roots to the object (WebappClassloader)', but still the WebappClassloader is not being garbage collected! Anyone encountered something like this before?

I'm using Tomcat 6.0.32


Sorry I didn't resolve this earlier...

I had eliminated all of the GC roots to WebappClassloader, but it was just not being garbage-collected. I tried forcing garbage collection, to no avail.

The problem was that calling Runtime.getRuntime().gc(); does not guarantee that everything possible will be garbage collected - only that the JVM will make its best effort to do so.

After reloading Tomcat a couple more times, the JVM started running low on PermGen space, the WebappClassloader was indeed garbage-collected. I assume that the JVM didn't GC it earlier because it didn't need to.

0

精彩评论

暂无评论...
验证码 换一张
取 消