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?


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 this article for details (specifically this part).


The GC throws this exception when too much time is spent in garbage collection for too little return, eg. 98% of CPU time is spent on GC and less than 2% of heap is recovered.

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.

You can turn this off with the command line option -XX:-UseGCOverheadLimit

More info here

EDIT: looks like someone can type faster than me :)


If you are sure there are no memory leaks in your program, try to:

  • Increase the heap size, for example -Xmx1g .
  • Enable the concurrent low pause collector -XX:+UseConcMarkSweepGC .
  • Reuse existing objects when possible to save some memory.
  • If necessary, the limit check can be disabled by adding the option -XX:-UseGCOverheadLimit to the command line.

    链接地址: http://www.djcxy.com/p/54988.html

    上一篇: Maven构建中的“java.lang.OutOfMemoryError:PermGen space”

    下一篇: 错误java.lang.OutOfMemoryError:超出GC开销限制