Skip to content
Fix Code Error

Error java.lang.OutOfMemoryError: GC overhead limit exceeded

March 13, 2021 by Code Error
Posted By: Anonymous

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?

Solution

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.
Answered By: Anonymous

Related Articles

  • When I'm testing a web app by JUnit and Mockito I get many…
  • JUNIT @ParameterizedTest , Parameter resolution Exception
  • ClassNotFoundException thrown
  • How to parse JSON file with Spring
  • Mock MQRFH2 header in JUnit Testing Error [MQRFH2 has…
  • Virtual Memory Usage from Java under Linux, too much memory…
  • Execution failed for task ':app:compileDebugJavaWithJavac'…
  • Gradle error: Execution failed for task…
  • Jetpack Compose and Hilt Conflict
  • How I can resolve exception java.lang.NoSuchFieldError:…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How do I pass environment variables to Docker containers?

Next Post:

How do I use $scope.$watch and $scope.$apply in AngularJS?

Leave a Reply Cancel reply

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

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error