views:

73

answers:

1

After stopping my web app, a significant amount of PermGen is not being released. The culprit seems to be the WebappClassLoader (in Tomcat, but it happens in Jetty too), which is kept in memory by references from a bunch of other objects. The following image shows that objects that refer to WebappClassLoader, and the things that refer to them, and so on.

alt text

One of the clingy objects seems to be an instance of net.lag.logging.Level$INFO$, to which a reference is stored in the static known array in java.util.logging.Level.

It appears that java.util.logging.Level keeps a static reference to all instances of itself. Bad, nasty java.util.logging.Level! Can I do anything about it? The java.util.logging framework is used by a third-party library, so I don't think I have the option of not using it.

+1  A: 

Short of making Sun fix the Level implementation or changing your library to do away with its custom Level, the only way I can think of is moving the library out of the web application classloader and into the container (shared or common classloader).

If you do this, there will still be the custom instances of Level, but they will no longer be linked to the web application. So that if you bounce the webapp, it will keep recycling the same Levels (not leaking new ones).

Of course, this will affect the classloader for the library, and it might break. Some things need to be in the web application and cannot be moved to the container. Even if the library continues to work, it might itself keep similar references to other parts of the web application around, which would be the exact same problem again. Still, give it a try.

Thilo