Q:

Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded

I can't run my process. It gives the following exception: "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space"

java -Xms32m -Xmx516m FilteringSNP_genus
  Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
          at java.util.Arrays.copyOf(Arrays.java:2882)
          at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
          at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:515)
          at java.lang.StringBuffer.append(StringBuffer.java:306)
          at java.io.BufferedReader.readLine(BufferedReader.java:345)
          at java.io.BufferedReader.readLine(BufferedReader.java:362)
          at FilteringSNP_genus.main(FilteringSNP_genus.java:65)

I have tried different memory usage configurations like:

java -Xms32m -Xmx1024m FilteringSNP_genus

but it has not worked, and increasing the -XmxVALUE has given a GC overheadlimit exceeded exception:

Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
          at java.lang.String.substring(String.java:1940)
          at java.util.StringTokenizer.nextToken(StringTokenizer.java:335)
          at FilteringSNP_genus.main(FilteringSNP_genus.java:77)

Could anyone provide some clue to fix this?
Thanks

A:

I'd hazard a guess that you're reading from a file or a socket and using readLine() for convenience without considering the implications. Try reading into a char[] buffer instead.
Alternately, you're reading lines in and storing hard references to them in memory, so you obviously will run out of room once you read enough.
As for the GC overhead error, according to an Oracle JVM article:
"The parallel collector will throw an OutOfMemoryError if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown."

