3

I read this stack overflow page about solving this problem and tried adding the command line option -XX:-UseGCOverheadLimit and also "-Xmx" arguments. However, my program still threw the out of memory error.

The program saves a large number (>40,000 keys) of words into a MultiKeyMap and is running on a server with plenty of memory.

Any suggestions on how I can aviod the error?

Community
  • 1
  • 1
user1253952
  • 1,577
  • 8
  • 22
  • 34

3 Answers3

4

If your problem is reliably reduced (to be honest, even if it's not) I suggest activating the -XX:+HeapDumpOnOutOfMemoryError JVM flag. This will, when there is an OutOfMemoryError, produce a binary dump of the memory. This can then be analysed by tools such as Eclipse MAT to identify potential memory leaks and help to explain why the Garbage Collector is having such a hard time clearing out your objects.

Rich
  • 15,602
  • 15
  • 79
  • 126
  • +1 `-XX:-HeapDumpOnOutOfMemoryError` is OFF and the default. To turn it ON you need `-XX:+HeapDumpOnOutOfMemoryError` In the documentation it always shows you what the default option is which means if you copy that option it shouldn't do anything. (Very confusing IMHO) You have to switch the `-` for `+` and visa-versa to do something. – Peter Lawrey Oct 10 '12 at 07:21
  • My fault - I can never remember the *precise* invocation so I searched for it and copied the first snippet that Google returned without even clicking on the link to see the context. I'll correct it. – Rich Oct 10 '12 at 07:24
  • 1
    I've edited the answer to change the flag following @PeterLawrey's remark. – Rich Oct 10 '12 at 07:24
1

This problem means that Garbage Collector cannot free enough memory for your application to continue. So even if you switch that particular warning off with "XX:-UseGCOverheadLimit" your application will still crash, because it consumes more memory than is available.

I would say you have memory leak symptoms. Either try digging in memory dump as suggested in another answer, or try Plumbr, which is memory leak monitoring tool created exactly for these situations.

Nikem
  • 5,716
  • 3
  • 32
  • 59
0

"GC Overhead limit" might be related to a memory leak, but it does not have to be the case. Based on the original question it is hard to say what the real problem is. You should have a "normal" Command line Config without all esotheric flags, and a sensible setting for Xmx to hold all your data. You should activate verbose gc logging to understand what GC is actually causing the overhead and tune it by changing the GC strategy or the generation sizes.

Usually the Overhead error come sup when you use structures that try to be memory friendly and use soft or weak references. If you use them on your own, double check that you understand what they do, because they can easily be misunderstood.

Fabian Lange
  • 1,786
  • 1
  • 14
  • 18