1

I've got a javaws (JNLP) app that will occasionally give

java.lang.OutOfMemoryError: Java heap space

but right after it happened the customer hit "m" in the console (to get memory usage) and "g" (to trigger an manual full GC) and I see

Memory: 1,013,632K  Free: 167,815K  (16%) ... completed.
Garbage collect ... completed.
Memory: 1,013,632K  Free: 760,924K  (75%) ... completed.

which to me looks like plenty of free memory even before the GC and tons after. I've already doubled the memory from what it had before (which was plenty in most cases). The stacktrace is different each time. Can anyone suggest what might cause this and how to fix it?

This is not a duplicate of the other OutOfMemoryError questions! Those are pretty generic, this is asking specifically about a strange case where we seem to get the error when not actually out of memory.

dlipofsky
  • 289
  • 1
  • 4
  • 18
  • 4
    `but right after it` - that's key. JVM failed to allocate block and throw an exception. No memory from that attempt is actually allocated.Triggering GC has no effect to it (if OOM is thrown, JVM already did all its best to reclaim space). I guess that your app is trying to allocate huge block which is over heap limit. – rkosegi Nov 20 '18 at 20:03
  • It doesn't look like the JVM tried to do a GC, since a GC immediately after was able to reclaim most of the space (by your theory, the space for the failed malloc would be accounted for even in the line before the GC). And I don't believe my app was trying to allocate a huge block, especially since I have seen the OOM occur in totally unrelated parts of the code. – dlipofsky Nov 20 '18 at 21:13
  • 1
    Likely the unwinding of the stack until that OutOfMemoryException was caught and printed makes enough objects eligible for garbage collection, while they previously were not. Use a profiler to record and analyse your memory usage. – Mark Rotteveel Nov 23 '18 at 18:44

0 Answers0