Java "OutOfMemoryError: PermGen space" (Legacy JDK 7) - Fix in CI
By Daniel Zoghalchali·Latchkey
On JDK 7 and earlier, class metadata lived in a fixed-size "permanent generation" (PermGen). OutOfMemoryError: PermGen space means that region filled - too many loaded classes, heavy reflection/proxies, or repeated redeploys leaking classloaders. PermGen was removed in JDK 8 (replaced by Metaspace).
What this error means
On a legacy JDK, a build or app fails with java.lang.OutOfMemoryError: PermGen space, often after loading many frameworks/generated classes or after several hot redeploys in a long-lived process.
stack trace
Exception in thread "main" java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
Common causes
Too many loaded classes for the fixed PermGen
Large frameworks, dynamic proxies, and code generation load enough classes to exceed the default MaxPermSize on JDK 7.
Classloader leak across redeploys
A long-running JVM that reloads applications can leak classloaders, so PermGen grows until it is exhausted.
JDK 8+ removed PermGen entirely; class metadata lives in native Metaspace, which grows dynamically.
.github/workflows/ci.yml
- uses:actions/setup-java@v4with:distribution:temurinjava-version:'21' # no PermGen; uses Metaspace
How to prevent it
Run on a supported JDK (8+) where PermGen no longer exists.
On legacy JVMs, size -XX:MaxPermSize for the framework/class load.
Fix classloader leaks in long-lived processes rather than just enlarging PermGen.
Frequently asked questions
What causes ""OutOfMemoryError: PermGen space""?
Large frameworks, dynamic proxies, and code generation load enough classes to exceed the default MaxPermSize on JDK 7.
How do I fix "OutOfMemoryError: PermGen space"?
As a stopgap on JDK 7, give PermGen more room.
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.