Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error java.lang.OutOfMemoryError: GC overhead limit exceeded

I get this error message as I execute my JUnit tests:

java.lang.OutOfMemoryError: GC overhead limit exceeded 

I know what an OutOfMemoryError is, but what does GC overhead limit mean? How can I solve this?

like image 434
Mnementh Avatar asked Sep 08 '09 11:09

Mnementh


People also ask

What does GC overhead limit exceeded mean?

GC Overhead Limit Exceeded Error VirtualMachineError. It's thrown by the JVM when it encounters a problem related to utilizing resources. More specifically, the error occurs when the JVM spent too much time performing Garbage Collection and was only able to reclaim very little heap space.

How do I stop OutOfMemory error in Java?

As explained in the above paragraph this OutOfMemory error in java comes when the Permanent generation of heap is filled up. To fix this OutOfMemoryError in Java, you need to increase the heap size of the Perm space by using the JVM option "-XX: MaxPermSize".

What causes Java Lang OutOfMemoryError Java heap space?

lang. OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further.

When the Java Virtual Machine Cannot allocate an object and no more memo made available by the garbage collector What is the error it will throw?

Usually, this error is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory. No more memory could be made available by the garbage collector.


1 Answers

This message means that for some reason the garbage collector is taking an excessive amount of time (by default 98% of all CPU time of the process) and recovers very little memory in each run (by default 2% of the heap).

This effectively means that your program stops doing any progress and is busy running only the garbage collection at all time.

To prevent your application from soaking up CPU time without getting anything done, the JVM throws this Error so that you have a chance of diagnosing the problem.

The rare cases where I've seen this happen is where some code was creating tons of temporary objects and tons of weakly-referenced objects in an already very memory-constrained environment.

Check out the Java GC tuning guide, which is available for various Java versions and contains sections about this specific problem:

  • Java 11 tuning guide has dedicated sections on excessive GC for different garbage collectors:
    • for the Parallel Collector
    • for the Concurrent Mark Sweep (CMS) Collector
    • there is no mention of this specific error condition for the Garbage First (G1) collector.
  • Java 8 tuning guide and its Excessive GC section
  • Java 6 tuning guide and its Excessive GC section.
like image 93
Joachim Sauer Avatar answered Oct 02 '22 17:10

Joachim Sauer