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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →