Skip to content
Latchkey

Java "OutOfMemoryError: Compressed class space" in CI

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.

How to fix it

Raise the compressed class space

Increase the cap (and Metaspace alongside it).

Terminal
java -XX:CompressedClassSpaceSize=1g -XX:MaxMetaspaceSize=1g -jar app.jar

Reduce class-loading pressure

  1. Use a fresh JVM per build (--no-daemon) so class metadata does not accumulate.
  2. Lower test fork parallelism so fewer JVMs load the full class set at once.
  3. 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.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card