[Solved]: Error java.lang.OutOfMemoryError: GC overhead limit exceeded



Problem Statement:

I get this error message as I execute my program in eclipse:

java.lang.OutOfMemoryError: GC overhead limit exceeded

How to solve this problem?


Solution:

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


Method1: Best Solution

Just increase the heap size a little by setting this option in

Run → Run Configurations → Arguments → VM arguments

-Xms1024M -Xmx2048M

Xms – for minimum limit

Xmx – for the maximum limit


Method2: only go for method 2 when method 1 is not working

Enable the concurrent low pause collector with the command line option -XX:+UseConcMarkSweepGC


Method3: only go for method 3 when method 1 and 2 is not working

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 the 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



if you are not able to solve your problem then tell us in the comment section.