Troubleshooting guide
GC overhead limit exceeded in Java: how to fix it
The JVM spent nearly all its time in garbage collection and freed almost nothing, so it gave up. The heap is effectively full of live objects.
3 min read10 sectionsUpdated
On this page
# Recommended flags
java -Xlog:gc*:file=/var/log/gc.log:time \
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dumps \
-jar app.jar
# Live view of generation occupancy and GC time
jstat -gcutil PID 2000 10
# Top objects by retained count
jcmd PID GC.class_histogram | head -25
# Heap dump on demand (pauses the JVM)
jcmd PID GC.heap_dump /dumps/now.hprofFixes
Open the dump in Eclipse MAT, and use the Leak Suspects report. Fix what retains the memory: add eviction to caches, remove listeners, paginate queries. In containers use -XX:MaxRAMPercentage=75 rather than a fixed -Xmx. Then consider G1 or ZGC. Avoid -XX:-UseGCOverheadLimit: it simply removes the warning and lets the application stall until it hits a true out-of-memory error.
Leak or just too small?
Look at heap occupancy after full collections. If it rises across hours until it reaches the limit, you have a leak. If it levels off close to the maximum and rises with traffic, the heap is too small for your workload. A sawtooth with a stable baseline is healthy. In Eclipse MAT, the dominator tree shows which object keeps the most memory alive, and that is usually more telling than the histogram: a million byte[] instances mean little until you see that a single cache owns them.
Catch it automatically
Alert on GC time as a percentage of wall time, and on post-GC heap usage. JVM monitoring charts those next to request latency, which is where GC pressure shows up to users first.
Is this the same as a Java heap space error?
Both mean the heap is effectively full. This one is the JVM giving up early because GC is not productive.
Should I increase -Xmx?
Only after confirming that it is not a leak.
Do heap dumps affect production?
Yes. They pause the JVM, so take them on an instance out of rotation if possible.
Related reading
- PHP maximum execution time exceeded: how to fix it: Fix PHP Maximum execution time of 30 seconds exceeded: why external waits may not count, which timeouts line up with Nginx, and how to move long work away.
- JavaScript heap out of memory: how to fix it in Node.js: Fix FATAL ERROR: JavaScript heap out of memory. Set --max-old-space-size correctly, handle build-time failures and find runtime leaks with heap snapshots.
- 429 Too Many Requests: what it means and how to fix it: 429 Too Many Requests explained: rate limits, the Retry-After header, backoff with jitter for clients, and how to set fair rate limits on your own API.
- Elasticsearch monitoring: cluster health and performance: Monitor Elasticsearch and OpenSearch: cluster status, unassigned shards, JVM heap, search and indexing latency, thread pool rejections and disk watermarks.
- Apache "server reached MaxRequestWorkers": how to fix it: Fix Apache server reached MaxRequestWorkers setting: choose the right MPM, calculate workers from memory and move away from mod_php for better concurrency.
- Elasticsearch CircuitBreakingException: how to fix it: Fix Elasticsearch CircuitBreakingException Data too large: reduce fielddata and huge aggregations, size JVM heap correctly and check shard counts per node.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.