You are here : Home / Core Java Tutorials / Core Java tutorial in detail / Exceptions Tutorial in java / OutOfMemoryError
Contents of page >
Read : OutOfMemoryError in java
1) Exception in thread threadName - java.lang.OutOfMemoryError: GC Overhead limit exceeded in java
OutOfMemoryError: GC Overhead limit exceeded - indicates that the garbage collector is running all the time and Java program is making very slow progress.
After a GC (garbage collection), if the garbage collector is spending more than 98% of its time in doing garbage collection and if less than 2% of the java heap memory space is reclaimed, then OutOfMemoryError - GC Overhead limit exceeded - is thrown in java.
This OutOfMemoryError is generally thrown because all the live objects are not getting garbage collected properly and java heap space is not available for new objects.
2) How to avoid OutOfMemoryError - GC Overhead limit exceeded in java?
You must increase the heap size to avoid OutOfMemoryError - GC Overhead limit exceeded in java as a solution to this issue.
3) How to turn off OutOfMemoryError - GC Overhead limit exceeded in java?
You can turn it off by using VM (JVM) argument -XX:-UseGCOverheadLimit
4) Example/Program in java to generate OutOfMemoryError: GC Overhead limit exceeded >
-Xmx4m -XX:+UseParallelGC (so that we could easily produce OutOfMemoryError: GC Overhead limit exceeded)
package outofmemory;
import java.util.ArrayList;
import java.util.List;
/**
*
* Write a program which could throw
* java.lang.OutOfMemoryError : GC Overhead limit exceeded
*
*/
public class OutOfMemoryErrorGCoverheadLimitExceeded {
static List<String> list=new ArrayList();
public static void main(String[] args) {
while(true){
list.add(new String("a")); //Line 16
}
}
}
|
OUTPUT of program >
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at outofmemory.OutOfMemoryErrorGCoverheadLimitExceeded.main(OutOfMemoryErrorGCoverheadLimitExceeded.java:16)
The solution is simply to increase the Xmx parameter to -Xmx512m as we discussed above.
5) Summary -
So in this tutorial we learned OutOfMemoryError: GC Overhead limit exceeded - indicates that the garbage collector is running all the time and Java program is making very slow progress. And how to produce solve this OutOfMemoryError issue with example in java.
To avoid OutOfMemoryError - GC Overhead limit exceeded in java - You must increase the heap size.
To turn off OutOfMemoryError - GC Overhead limit exceeded in java >
-XX:-UseGCOverheadLimit
Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.
RELATED LINKS>