0

I'm getting java.lang.OutOfMemoryError in one of my java application. I increased size of minimum and maximum heap size under "VM arguments" in eclipse:

-XX:+HeapDumpOnOutOfMemoryError -Xmx8g -Xms2g However, I'm still getting same error. In jconsole.exe it displays the following: jconsole screenshot

If I understood correctly, then I still have plenty of heap memory.

I also analyzed the memory dump using eclipse MAT MAT screenshot

As you can see, it shows problem but only 9 MB. So what's exactly the problem? shouldn't I have enough free heap memory?

Anthony J.
  • 375
  • 1
  • 5
  • 14
  • 1
    Looks like your problem is not available memory but [memory leaks](https://en.wikipedia.org/wiki/Memory_leak). No matter how much memory you assign, it will eventually throw an OOM. – m0skit0 Nov 30 '16 at 14:44
  • Could you indicate your java version/platform, and put the full Exception Message? It may be a permgen error if <=1.7,... – pdem Nov 30 '16 at 14:51
  • @pdem I have 1.8 64bit. Full message "java.lang.OutOfMemoryError: Java heap space" then it prints the stack trace. As m0skit0 and JensB mentioned, it's related to memory leak that needs to be fixed and increasing heap memory won't solve the problem – Anthony J. Nov 30 '16 at 15:07

1 Answers1

1

Not strictly relating to java but this can also be caused by trying to store something in your memory that can't fit all in one place.

Consider a car parking lot with metal bars between each parking space. There are 20 empty motorcycle spots. You want to park your SUV. Even though the total area of the available space is greater than your vehicles requirement you still can't park as it cant fit in any single spot.

I dont know if this is the case here, but this is the most common reason I run into this problem.

Are you trying to store something significantly larger than anything else anywhere near where this error happens?

JensB
  • 6,663
  • 2
  • 55
  • 94
  • thanks for the explanation. I guess I have to do deeper debugging then, the code actually is not mine and it will take time to debug and understand it. I was curious as to why increasing heap size didn't resolve the problem. – Anthony J. Nov 30 '16 at 15:02
  • You are right. I found the problem, it was trying to create array of "1836020326" items! this number was incorrectly parsed from wrong string data. – Anthony J. Nov 30 '16 at 15:44