Error java.lang.OutOfMemoryError: GC overhead limit exceeded
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.
Spring Boot application- problem with java.lang.OutOfMemoryError: GC overhead limit exceeded
My SpringBoot app have a problem with
java.lang.OutOfMemoryError: GC overhead limit exceeded
.I can see log as below:
Handler dispatch failed; nested exception is
java.lang.OutOfMemoryError: GC overhead limit exceeded.
That is a common error.
It means that your application's JVM is spending too much time running the garbage collector. It typically happens because you have nearly run out of space, and the GC is having to run more and more often to keep going.
Additionally, cpu is very high when I working in the application(99%).
That is to be expected; see above.
I think that it is connected with xmx.
Yes it is connected with that.
One possibility is that the task your webapp is doing needs needs more memory than is allowed by the -xmx
setting. Increasing -xmx
will solve the problem ... until you get to a larger task. At that point you need to see if you can optimize memory usage, or buy a machine with more memory. (How much money do you have in the bank?)
Another possibility is that your webapp has a memory leak. If that is the problem then increasing -xmx
doesn't solve the problem. Your webapp is liable to run into OOME's again ... though it may take longer for it to happen.
I suggest that you find and read a good article on fixing memory leaks. Assume that it is a leak ... until you find clear evidence that it is not.
So how can I check the xmx size set for this application?
It depends on how you are running the springboot application. For example, this article explains how to do it with an embedded Tomcat.
- How can I configure the heap size when starting a Spring Boot application with embedded Tomcat?
Why do I keep getting a GC overhead limit exceeded and sometimes Heap Size error in jsp?
GC overhead limit exceeded will come, if your application is spending too much of time on GC.
This error means that the GC tried to free memory but was pretty much unable to get anything done. By default it happens when the JVM spends more than 98% of the total time in GC and when after GC less than 2% of the heap is recovered.
You neeed to examine your application and close the resources so that they can be freed by GC
Why does Spark fail with java.lang.OutOfMemoryError: GC overhead limit exceeded?
Adjusting the memory is probably a good way to go, as has already been suggested, because this is an expensive operation that scales in an ugly way. But maybe some code changes will help.
You could take a different approach in your combine function that avoids if
statements by using the combinations
function. I'd also convert the second element of the tuples to doubles before the combination operation:
tuples.
// Convert to doubles only once
map{ x=>
(x._1, x._2.toDouble)
}.
// Take all pairwise combinations. Though this function
// will not give self-pairs, which it looks like you might need
combinations(2).
// Your operation
map{ x=>
(toKey(x{0}._1, x{1}._1), x{0}._2*x{1}._2)
}
This will give an iterator, which you can use downstream or, if you want, convert to list (or something) with toList
.
Obfuscating app with R8 causes GC overhead limit exceeded
Add in gradle.properties
org.gradle.jvmargs=-Xmx4096m
This issue as @Stephen C pointed out in comments can be solved by increasing heap size like above.
In my case JVM initial heap size was around 1.5GB. I just increased to 4GB. And everything works fine now.
You can Check your default HeapSize with (In android studio terminal)
In Windows:
java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize ThreadStackSize"
In Linux:
java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'
Then increase it accordingly
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded Android Studio
Just add below lines to your build.gradle file.
dexOptions {
javaMaxHeapSize "4g"
}
I hope this will help you.
Related Topics
How Does the Java Cast Operator Work
What Are the Pros and Cons of Performing Calculations in SQL VS. in Your Application
Jtable How to Change Background Color
Why Do I Get "Non-Static Variable This Cannot Be Referenced from a Static Context"
Understanding Spring @Configuration Class
Javafx Launch Another Application
Best Way to Get Geo-Location in Java
Are There Best Practices for (Java) Package Organization
Rotate Bufferedimage Inside JPAnel
Nullpointerexception Through Auto-Boxing-Behavior of Java Ternary Operator
What Is the Most Efficient Java Collections Library
Does Java Support Let's Encrypt Certificates
What Is the Default Stack Size, Can It Grow, How Does It Work with Garbage Collection