Is MetaSpace by default is GC collected?
Yes, GC will run on metaspace when its getting full, it would also
dynamically increase (given its allowed to) the memory allocated for
metadata.
Even the PermGen is GC collected by adding the args like -XX:+CMSClassUnloadingEnabled, then what makes MetaSpace better than PermGen?
The improvement is with the dynamic expansion of the metaspace which
is something permgen wasn't able to do.
MetaSpace is based on native memory, so it keeps the java objects on the disks rather than on VM?
Based on the description of metaspace, it only uses the native memory
(no paging).
Based on the research by Pierre - Hugues Charbonneau (link here), it's clear that the introduction of metaspace doesn't necessarily solve the OOM issue, it's a bandaid to the problem at best, it attempts to dynamically resize the metaspace memory to accomodate the growing number of classes which get loaded with a possible side effect of growing uncontrollably (so long as the native memory permits it).
We can achieve the famed OOM error by setting the MaxMetaspaceSize
argument to JVM and running the sample program provided.
many thanks to Pierre - Hugues Charbonneau.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…