I have a J2EE application with some interesting behavior ... the heap seems to behave well, growing and shrinking with garbage collections as expected over time. There is no app
The main cause for the java.lang.OutOfMemoryError: Metaspace is:
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
Do a heap dump and analyze it with Eclipse MAT. Look at the classes you have loaded. Check if there's something unexpected, especially duplicate classes. It also has a classloader explorer.
Edit: In theory you could also be that you're constantly generating proxies.