views:

17576

answers:

3

I get this errormessage as I execute my JUnit-Tests:

java.lang.OutOfMemoryError: GC overhead limit exceeded

I know OutOfMemoryError, but what does GC overhead limit mean, and how can I exceed this?

EDIT: I resolved the problem, but thanks to your answers I learned something new about the JVM.

+36  A: 

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).

Joachim Sauer
Would it be correct to summarise your answer as follows: "It's just like an 'Out of Java Heap space' error. Give it more memory with -Xmx." ?
Tim Cooper
@Tim: No, that wouldn't be correct. While giving it more memory *could* reduce the problem, you should also look at your code and see why it produces that amount of garbage and why your code skims just below the "out of memory" mark. It's often a sign of broken code.
Joachim Sauer
+15  A: 

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 :)

dave
"You can turn this off..." but the OP most likely should not do this.
Stephen C
Can you tell me the difference between "-XX" and "-Xmx"? I was able to turn it off using the "-Xmx" option too.
Bart J
A: 

I use the same option, it didn't give much more improvement. Again Still throws the same exception.

Thilip