【发布时间】:2020-09-01 11:17:41
【问题描述】:
我正在尝试实例化一个巨大的ArrayList
List<Integer> list = new ArrayList<Integer>(Integer.MAX_VALUE);
在eclipse中运行它我得到:
java.lang.OutOfMemoryError: Requested array size exceeds VM limit
如果我这样做:
List<Integer> list = new ArrayList<Integer>(Integer.MAX_VALUE - 2);
我得到一个不同的错误:
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory failed; error='The paging file is too small for this operation to complete'
#
# there is insifficent memory for the Java Runtime Environment to continue.
我在 Eclipse 的运行配置中使用以下设置启动程序:-Xmx8G
那么这里的问题是什么?即使我增加到-Xmx16G 它仍然给出同样的错误
更新
我有点困惑,RAM的实际大小在这里重要吗?由于分页,进程不能访问无限的虚拟内存吗?
【问题讨论】:
-
您的计算机上有 16 GB 的 RAM 吗?
-
@Abra:不,只有 6GB。但这有关系吗?操作系统不做虚拟内存交换吗?
-
@Abra:
Can the operating system assign all its RAM to your java process我该如何检查?我不知道 -
@Abra:我得到
Invalid initial heap size: -Xms=4G -
你并不真的需要这么大的数组,对吧?
标签: java operating-system hardware virtual-memory java-heap