When is Jdk 8 Metaspace garbage collected
- Garbage collection of the dead classes and classloaders is triggered once the class metadata usage reaches the “MaxMetaspaceSize”.
- Proper monitoring & tuning of the Metaspace will obviously be required in order to limit the frequency or delay of such garbage collections. Excessive Metaspace garbage collections may be a symptom of classes, classloaders memory leak or inadequate sizing for your application.
Garbage collection of the dead classes and classloaders is triggered once the class metadata usage reaches the “MaxMetaspaceSize” which by default is
"unlimited" so a proper monitoring is required to limit the delay or frequency of such GC.
You may want to set one or several of the following options:
-XX:MetaspaceSize=100M to increase the initial size of Metaspaces (the default is 16M);
-XX:InitialBootClassLoaderMetaspaceSize=32M to increase the boot class loader Metaspace;
-XX:MinMetaspaceFreeRatio=50 to make Metaspaces grow more agressively;
-XX:MaxMetaspaceFreeRatio=80 to reduce the chance of Metaspaces shrinking;
-XX:MinMetaspaceExpansion=4M the minumum size by which a Metaspace is exanded;
-XX:MaxMetaspaceExpansion=16M the maximum size to expand a Metaspace by without Full GC.