Ph3n1x
Ph3n1x

Reputation: 317

OutOfMemoryError when loading 100MB file, despite 550MB heap

following problem:

  1. I start my developed program (-Xmx550M)
  2. I load a 90 MB file

This loading is the peak of the used heap in the picture below. After this, the heap size increases from 130 to 500 MB, although only 110 MB are needed.

Well ok, no problem, annoying, but ok. But if I now start a save process (which needs ~100 MB) the Java VM crashes with the java.lang.OutOfMemoryError: Java heap space exception.

Heap Size and Used Heap (-Xmx550M)

If I started the application with 750 MB heap size, it works fine. You see the short peak and it works fine: Heap Size and Used Heap (-Xmx750M)

Now my question: Why the hell do I get an OutOfMemoryError with 550 MB Heap Size? The application only needs 400 MB (at the highest peak)!

I do not know how to fix that :(

Please help me!

Upvotes: 4

Views: 5106

Answers (2)

Peter Lawrey
Peter Lawrey

Reputation: 533870

The data is sampled. Just before it failed it was using 400 MB, and then some time later it tried to use more memory e.g. 600 MB but this didn't show because by the time the next sample was taken the OOME had happened and you usage is now much lower.

In short, your program can use memory faster than you can see in the graphs.

Upvotes: 1

Stepan Yakovenko
Stepan Yakovenko

Reputation: 9216

If you load 100Mb file, it doesn't yet mean that structures, used for this file in memory occupy 100M. For instance, if you have String, you also have 4 byte overhead for its length.

Upvotes: 1

Related Questions