I always heard that Classloader
unloading was problematic. They are theoretically garbage collected when there is not reference to the object instances and class unloading is not necessary, but in practice it seems like to be more problematic. Subtle references may leak and prevent the Classloader
from being reclaimed. In application servers, after numerous redeploy cycle, I sometimes got a OutOfMemoryError: PermGen space
.
All that to say that I guess there is a nasty reference somewhere that prevent it from being collected — maybe the memory analyzer didn’t followed the link correctly. It seems like all this can happen, as described in these articles:
- Classloader leaks: the dreaded PermGen space exception
- How to fix the dreaded PermGen space exception
Also, I don’t know exactly what you are doing, but if you can wait for JDK 7, you could have a look at AnonymousClassLoader
. They will be introduced to better support dynamic language, as explained in this post:
- A first taste of InvokeDynamic
I hope it will help you.