I am running jvm 1.8.0_65 and using Groovy to load classes dynamically, the Groovy version is 2.4.7. I turned on class unloading by adding "-XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:+TraceClassUnloading -Dgroovy.use.classvalue=true". But the classes loaded by Groovy won't unload on GC. I also loaded native Java classes in the same application, and these classes got unloaded as expected when garbage collected.
I analyzed the heap dump by MAT, and could not find any references to GC root that is not a weak reference, here are some screen shots:
The Class's path to GC Roots excluding weak/soft references
The classloader's path to GC Roots excluding weak/soft references
Things referencing the classloader.
So I really don't know what's stopping the JVM from unloading these classes. Any help is greatly appreciated!