java.lang.OutOfMemoryError: GC overhead limit exceeded
The JVM spent over 98 percent of recent time collecting and recovered less than 2 percent of the heap, so it stopped rather than crawling on. The heap need not be full: a cache holding strong references keeps everything reachable, and the collector works harder each cycle for less return.
Quick fix
Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.
# Capture the evidence before restarting, or you will wait for it again
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/app/
-Xlog:gc*:file=/var/log/app/gc.log:time,uptime:filecount=5,filesize=10M
# Read the dump: the dominator tree names the retaining object
# Eclipse MAT dominator tree: look for the one map holding most of the heap
jcmd <pid> GC.heap_info
jcmd <pid> GC.class_histogram | head -20
# Raising -Xmx buys time and hides a leak: do it only once the histogram
# shows a legitimately large working set
# Common causes, in order: an unbounded cache, a ThreadLocal never cleared,
# a ClassLoader retained by a redeploy, string keys built per request
# The switch exists but silences the symptom rather than the cause
-XX:-UseGCOverheadLimit
How to diagnose Performance errors
Performance failures rarely produce an error message. They produce timeouts elsewhere. The three classic causes are stop-the-world garbage collection, thread pool starvation (all workers blocked on I/O so new requests queue), and event loop blocking in single-threaded runtimes. All three look identical from outside: latency climbs, then upstream timeouts fire. Distinguishing them requires looking inside the process.
If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.
- Measure the p99, not the mean. Averages hide exactly the pauses that cause timeouts.
- For the JVM, enable GC logging (
-Xlog:gc*) and correlate pause durations with latency spikes before tuning anything. - For thread pools, log active versus queued task counts. A queue that grows while CPU is idle is starvation, and the fix is asynchronous I/O, not more threads.
- In Node.js, measure event loop lag directly (
perf_hooks.monitorEventLoopDelay). Any synchronous work over a few milliseconds per request will show up here. - Profile before optimising.
pprof,async-profiler,py-spyand Chrome's profiler all point at the real hot path, which is rarely where intuition suggests.
Tools worth reaching for
async-profilergo tool pprofpy-spyperf_hooks.monitorEventLoopDelay-Xlog:gc*
Authoritative references
Primary documentation for this error, worth reading before applying any fix in production.
Related Performance errors
- Container CPU throttling: nr_throttled rising in cpu.statA CPU limit is enforced as a quota per 100ms period, so a process that spends its quota early…
- Long GC pause / stop-the-world latency spikeA managed runtime paused application threads to collect garbage long enough to violate…
- Node.js: event loop lag / blocked synchronouslyCPU-bound work or sync I/O blocked Node's single event loop thread, delaying unrelated…
- Node.js: high latency from synchronous crypto or JSON on the event loopNode runs JavaScript on a single thread. A synchronous bcrypt hash, a large JSON.parse, or a…
- Thread pool starvation / requests queueing behind blocked threadsAll threads in a bounded pool are blocked on I/O, locks, or sync-over-async calls. Latency…
Browse other categories
- HTTP 494xx client errors, 5xx server errors, redirects, headers and protocol problems.
- JavaScript 42npm resolution, async pitfalls, hydration, memory limits and runtime type…
- Database 41Connections, deadlocks, constraints, replication and memory limits.
- AI 35Rate limits, context windows, GPU memory and model-serving failures.
- Network 35Refused connections, timeouts, resets, MTU problems and port exhaustion.
- Python 35Imports, virtual environments, encoding, concurrency and dependency conflicts.
- Kubernetes 34CrashLoopBackOff, ImagePullBackOff, OOMKilled, RBAC, scheduling and storage.
- Docker 27Daemon connectivity, disk space, image pulls, ports and architecture mismatches.
- System 26Disk space, systemd units, file descriptors, OOM killer and scheduled jobs.
- Cloud 25IAM permissions, quotas, service limits and credential failures.
- Security 25JWT validation, CSRF, OAuth grants, SELinux, SSH host keys and CSP.
- TLS 24Untrusted authorities, expiry, hostname mismatch, chains and cipher negotiation.
Something missing or wrong?
This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.