Kailash
Kailash

Reputation: 785

Java out of memory error when memory is in fact available

I keep running into OOM errors and subsequent JBoss crashes, even though the heap shows that all of the memory allocated to it isn't used up.

For eg: If I have 1200MB allocated as the heap size (Xmx), crashes occur well below that limit with none of the individual generations in the heap (young / old / perm) at a 100%.

The box has plenty of RAM. Why might java be reporting this error when its really not out of memory?

 Heap

 PSYoungGen      total 67456K, used 9525K [0x57540000, 0x5c170000, 0x5fa90000)
  eden space 66432K, 12% used [0x57540000,0x57d91520,0x5b620000)
  from space 1024K, 98% used [0x5c070000,0x5c16c198,0x5c170000)
  to   space 3008K, 0% used [0x5bb90000,0x5bb90000,0x5be80000)

 PSOldGen        total 466048K, used 313530K [0x14a90000, 0x311b0000, 0x57540000)
  object space 466048K, 67% used [0x14a90000,0x27cbea38,0x311b0000)

 PSPermGen       total 226432K, used 141461K [0x04a90000, 0x127b0000, 0x14a90000)
  object space 226432K, 62% used [0x04a90000,0x0d4b55e8,0x127b0000)

Upvotes: 4

Views: 1739

Answers (2)

Stephen C
Stephen C

Reputation: 719426

Yes it is possible to get an OOME when you've still got plenty of free heap space.

When you create a thread the JVM needs to allocate memory for the thread's stack. However the JVM doesn't allocate the thread stack in the heap. (The thread stack needs to be in memory that won't be moved by the garbage collector.) Instead, it requests it directly from the OS. If the OS can't satisfy that request, you get an OOME ... irrespective of your heap size.

Apparently, an OOME can also occur during thread creation if your application exceeds the operating system's per-process thread limit. (On Linux / Unix this is controlled by ulimit -u ...)


It is a bit difficult to say what is happening in your case. I suspect that your application is simply trying to create too many threads and running into one of the limitations above. You could try reducing the thread stack size, but a better approach would be to figure out why you are creating so many threads and stop it. (Huge numbers of threads tend to waste resources ... and make your application slower in various ways.)

Upvotes: 3

Jamie McCrindle
Jamie McCrindle

Reputation: 9204

Have a look at this answer on the JBoss community site as to why you'd get the Unable to create a new thread OOM

Upvotes: 2

Related Questions