简体   繁体   English

加载 100MB 文件时出现 OutOfMemoryError,尽管有 550MB 堆

[英]OutOfMemoryError when loading 100MB file, despite 550MB heap

following problem:以下问题:

  1. I start my developed program (-Xmx550M)我开始我开发的程序(-Xmx550M)
  2. I load a 90 MB file我加载了一个 90 MB 的文件

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.在此之后,堆大小从 130 MB 增加到 500 MB,尽管只需要 110 MB。

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.但是,如果我现在开始一个保存过程(需要约 100 MB),Java VM 会因 java.lang.OutOfMemoryError: Java heap space 异常而崩溃。

堆大小和已用堆 (-Xmx550M)

If I started the application with 750 MB heap size, it works fine.如果我以 750 MB 的堆大小启动应用程序,它工作正常。 You see the short peak and it works fine:你会看到短峰,它工作正常:堆大小和已用堆 (-Xmx750M)

Now my question: Why the hell do I get an OutOfMemoryError with 550 MB Heap Size?现在我的问题是:为什么我会得到 550 MB 堆大小的 OutOfMemoryError? The application only needs 400 MB (at the highest peak)!该应用程序仅需要 400 MB(在最高峰时)!

I do not know how to fix that :(我不知道如何解决这个问题:(

Please help me!请帮我!

If you load 100Mb file, it doesn't yet mean that structures, used for this file in memory occupy 100M.如果加载 100Mb 的文件,并不意味着内存中用于该文件的结构占用 100M。 For instance, if you have String, you also have 4 byte overhead for its length.例如,如果您有 String,那么它的长度也有 4 个字节的开销。

The data is sampled.数据被采样。 Just before it failed it was using 400 MB, and then some time later it tried to use more memory eg 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.就在它失败之前它使用了 400 MB,然后一段时间后它尝试使用更多的内存,例如 600 MB 但这没有显示,因为到下一个样本被采集时,OOME 已经发生,现在你的使用率要低得多.

In short, your program can use memory faster than you can see in the graphs.简而言之,您的程序可以比您在图表中看到的更快地使用内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM