Video in progress

Strong Junior ⚙️ JVM and memory

What situation does the "GC overhead limit exceeded" error indicate?

The JVM is spending almost all its time (more than 98%) on GC, yet each time it frees less than 2% of the heap. Instead of "freezing and dying slowly", the JVM throws this OOM to stop the program.

📖 Answer

This is also an OutOfMemoryError, just in a different form. The heap is effectively full, but each GC finds a little room and the application moves forward a bit. As a result the service looks like it is running, but in reality the GC eats the CPU and requests don't get answered.

This check is specific to Parallel GC (-XX:+UseGCOverheadLimit, on by default). With G1 this message usually doesn't appear; there you see long Full GCs and in the end a plain Java heap space.

The causes are the same as for Java heap space:

  • a memory leak;
  • a heap that is small relative to the load;
  • loading a very large amount of data fully into memory.

One wrong piece of advice is common: turning the check off with -XX:-UseGCOverheadLimit. It doesn't solve the problem: the service still crashes with Java heap space, it just stays in a "dead state" for longer first.

The right way: take a heap dump, see what is occupying the memory, then either fix the leak or raise -Xmx with a reason.