ClassLoader
s are stored in Permanent generation memory . And as specified in white paper of java Memory Management in the Java HotSpot™ Virtual Machine, permanent generation memory is garbage collected for sure. So, Does custom Classloader
still lead to memory leakage? If yes, then how come that it happens?
UPDATE
With the help of @Marko Topolnik and @Prunge I got my doubt clear. And following points are made out about ClassLoaders and Memory Leaks:
- Custom
ClassLoader
s are not stored in Perm generation. - Custom
ClassLoader
could lead to memory leakage ifClassLoder
is out of scope but the classes that it has loaded is still referred by the Application no matter if we set theClassLoader
object tonull
. - If we don't need a given
ClassLoader
object then we should make sure that all the references to the objects developed from loaded classes should benull
. - If any of the classes loaded by
ClassLoader
is not eligible forGC
then the ClassLoader will not beGCed
.