I'm trying to generate classes and load them at run time.
I'm using a ClassLoader
object to load the classes. Since I don't want to run out of PermGen
memory, from time to time I un-reference the class loader and create a new one to load the new classes to be used. This seems to work fine and I don't get a PermGen
out of memory.
The problem is that when I do that, after a while I get the following error:
java.lang.OutOfMemoryError: GC overhead limit exceeded
So my question is, when should I un-reference the class loader to avoid both errors?:
Should I monitor in my code the PermGen
usage so that I un-reference the class loader and call System.gc()
when the PermGen
usage is close to the limit?
Or should I follow a different approach?
Thanks