The main cause for the java.lang.OutOfMemoryError: Metaspace is:
- either too many classes or
- too big classes being loaded to the Metaspace.
If you want to recreate the problem use this code snippet:
public class Metaspace {
static javassist.ClassPool cp = javassist.ClassPool.getDefault();
public static void main(String[] args) throws Exception {
for (int i = 0; ; i++) {
Class c = cp.makeClass("eu.plumbr.demo.Generated" + i).toClass();
}
}
}
All those generated class definitions end up consuming Metaspace.
Javaassist in Maven repo.
You can find a lot more about OOME here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…