Since there's a memory leak in metaspace caused by class loader(last post), I found a classloader-leak-prevention library and used it.
I found if set -XX:MaxMetaspaceSize
(not -XX:MetaspaceSize
) to a appropriate value, from 164m to 180m in my case, the metaspace size would reduce after each hot loading. Though each hot loading will lead to OOM but afterwhile the application worked fine.
But set -XX:MaxMetaspaceSize to other value finally lead to OOM and the application cannot continue.
set to 256M:
It looks like to reduce the metaspace size after each hot loading there's must a gc triggered, and the gc seems has some relevance with -XX:MaxMetaspaceSize
. But the choice of the value is really a mystery.
Why there's a difference for various value of -XX:MaxMetaspaceSize
?