What is ‘java.lang.OutOfMemoryError: GC overhead limit exceeded’?

‘GC overhead limit exceeded’ is another kind of error that can occur when hosting your Java application on external Java host running JVM with different heap settings than your development environment. What documentation says:

Excessive GC Time and OutOfMemoryError
The parallel collector will throw an OutOfMemoryError if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown. This feature is designed to prevent applications from running for an extended period of time while making little or no progress because the heap is too small. If necessary, this feature can be disabled by adding the option -XX:-UseGCOverheadLimit to the command line.

Common solutions in this case are:
1) Optimize your code to use less memory and/or reuse objects instead of creating new ones thus reducing the number of times the garbage collector runs. If you create a lot temporary objects (e.g in a loop) you should try to reuse them.
2) Increase heap size using Xmx switch e.g. -Xmx512m (you can help yourself finding correct value by connecting to your JVM with JXM and Jconsole).
3) Disable the error check using -XX:-UseGCOverheadLimit
The third approach will only result in another kind of error messages – heap related java.lang.OutOfMemoryError.
4) Add -XX:+HeapDumpOnOutOfMemoryError to JAVA_OPTS and analyse the dump with IBM Memory Analyzer (part of IBM Support Assistant Workbench) looking for memory leaks (see references).

You may also try to change Garbage Collector Policy with
-XX:+UseConcMarkSweepGC concurrent (low pause time) garbage collector (also known as CMS), or
-XX:+UseParallelGC parallel (throughput) garbage collector.

References / See also:
Tuning Garbage Collection with the 5.0 Java TM Virtual Machine
4 Easy Ways to do Java Garbage Collection Tuning
Java Tuning White Paper
GC overhead limit exceeded – Java Heap analysis

This entry was posted in Java. Bookmark the permalink.

3 Responses to What is ‘java.lang.OutOfMemoryError: GC overhead limit exceeded’?

  1. Pingback: How To Fix Error Gc Overhead Limit Exceeded Pig in Windows

  2. pankaj gupta says:

    how & where put this command -XX:-UseGCOverheadLimit
    please provide the solution as soon as possible

Leave a Reply

Your email address will not be published. Required fields are marked *

× six = thirty

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>