java – OutOfMemoryError: GC overhead limit exceeded при параметрах -Xmx8192M -XX:-UseGCOverheadLimit


jUnit tests work with large amounts of data, in particular, this error occurs when we read data from the database into an object.

RAM – 16 GB, 4 virtual processors

when the error occurred

java.lang.OutOfMemoryError: GC overhead limit exceeded
at sun.reflect.GeneratedConstructorAccessor47.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
at java.lang.reflect.Constructor.newInstance(
at java.lang.Class.newInstance(

then I added the -XX:-UseGCOverheadLimit but got the following error:

java.lang.OutOfMemoryError: GC overhead limit exceeded
    at java.lang.reflect.Field.copy(
    at java.lang.reflect.ReflectAccess.copyField(
    at sun.reflect.ReflectionFactory.copyField(
    at java.lang.Class.copyFields(
    at java.lang.Class.getFields(

all JVM options -Xmx8192M -XX:-UseGCOverheadLimit

at the time the error appeared, the following system parameters were: RAM is stable at 46% (7400MB), CPU 77% -82% (82% at the time of the error)

tell me how to fix this problem?


  1. java.lang.OutOfMemoryError: GC overhead limit exceeded

This error can occur both when the first and second areas are overflowed. It is connected with the fact that there is little memory left and the GC is constantly working, trying to free up some space. This error can be disabled using the -XX: -UseGCOverheadLimit parameter, but, of course, you should not disable it, but either solve the memory leak problem, or allocate more space, or change the GC settings.

String object is too heavy. and I have a lot of thongs there. For example, we calculated a file that weighs 250 MB, has 1600 characters per line and 220,000 lines. I fill in ArrayList<String> lines , where each line is written as an object of 250 fields that take a value of 1600 characters. Such an object weighed a little over 6Гб .

Solution: increased the memory to 14Гб . now the problem is that the 6GB object does not fit on the heap, you have to think something else and sacrifice the test execution time.


In this case, the error java.lang.OutOfMemoryError: GC overhead limit exceeded indicates that you are trying to process such an amount of data that does not fit into memory. In the help you provided, it is mentioned that an error is thrown when the memory area occupied only by the created objects overflows. Plus, you can see in the stack trace that your classes (


) at the time of receiving the error, they are trying to unload data from the database.

Therefore, test the simple and disappointing conclusion from the above on a smaller amount of data or allocate a larger amount for unloading data (-Xmx12000M) if they fit there, then the error will disappear. It is useless to configure garbage collection in this case. The GC will not be able to remove the loaded objects because they are still in use.

Scroll to Top