In Java 6 we used to use the following GC configuration to prevent Perm Gen OutOfMemoryException
after several redeployments of our app:
-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled
We're moving to Java 7 and want to use the new G1 GC, which from what I've read, moves the classes from the PermGen in Java memory to native memory.
Is there some flag to enable unloading unused classes?
The G1 performs the class unloading during a Full GC, so you do not need to specify any parameters to enable this.
You can see for yourself by using the
-XX:+TraceClassUnloading
argument.Also, check out this email thread from the HotSpot GC mailing list: Bug in G1GC it performs Full GC when code cache is full resulting in overkill. They discuss class unloading in G1 quite extensively. In summary, you can use
-noclassgc
if you are seeing issues with class unloading but usually there are no problems with class unloading in G1.