Java "OutOfMemoryError: Compressed class space" in CI
By Daniel Zoghalchali·Latchkey
The JVM ran out of compressed class space - a sub-region of class metadata storage used when compressed class pointers are enabled. It is bounded by CompressedClassSpaceSize (default ~1 GB), separate from heap.
What this error means
A build or app with very many classes fails with java.lang.OutOfMemoryError: Compressed class space. Like Metaspace, raising -Xmx does not help - this is class-metadata memory.
JVM output
java.lang.OutOfMemoryError: Compressed class space
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
Common causes
CompressedClassSpaceSize too small for the class count
When tens of thousands of classes load (big frameworks, many generated classes), the compressed class space can fill before Metaspace does.
Classloader leak in a reused JVM
A long-lived daemon or app server that loads classes without unloading old classloaders leaks class metadata until the space is exhausted.
Use a fresh JVM per build (--no-daemon) so class metadata does not accumulate.
Lower test fork parallelism so fewer JVMs load the full class set at once.
Investigate classloader leaks in any long-lived process.
How to prevent it
Set CompressedClassSpaceSize/MaxMetaspaceSize generously when many classes load.
Prefer fresh JVMs in ephemeral CI.
Watch for classloader leaks in reused processes.
Frequently asked questions
What causes ""OutOfMemoryError: Compressed class space""?
When tens of thousands of classes load (big frameworks, many generated classes), the compressed class space can fill before Metaspace does.
How do I fix "OutOfMemoryError: Compressed class space"?
Increase the cap (and Metaspace alongside it).
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.