java - 创建二维 int 数组时出现内存不足异常

标签 java arrays performance

我有:

int [][] lengths=null;

我必须根据运行时参数初始化它。

当我的数组大小类似于 int[13000][130000] 或更大时,我收到 OutOfMemoryException

有没有办法解决这个问题或我可以采取的任何其他方法?

最佳答案

注意:这不应阻止 OutOfMemoryError,但您需要了解 JVM 内存参数,因为它应该对任何情况都有帮助.

您需要查看JVM内存参数。实际上,您可以为 JVM 设置尽可能多的内存:

-Xmx2048m -> this param to set the max memory that the JVM can allocate
-Xms1024m -> the init memory that JVM will allocate on the start up
-XX:MaxPermSize=512M -> this for the max Permanent Generation memory

您可能还想检查此参数。

-XX:MaxNewSize=  -> this could be 40% from your Xmx value
-XX:NewSize=614m -> this could be 40% from your Xmx value

您还可以告诉您JVM要使用什么类型的GC(我认为它已经在早期版本中默认使用)

-XX:+UseConcMarkSweepGC

关于java - 创建二维 int 数组时出现内存不足异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23263361/

相关文章:

java - 如何测试正在运行的线程在使用 JUnit 完成后是否正确终止

C程序函数错误

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

typescript - 如何调试 TypeScript 编译性能问题

java - 谷歌应用引擎: Poor Performance with JDO + Datastore

java - 对实例初始化感到困惑

java - 使用 Counter 类递增和递减 : java

c# - 最小的跨 AppDomain 通信性能损失是多少?

java - 无法更改 java.io.tmpdir

java - AudioRecord 并不总是记录预期的内容