我在 Eclipse 中使用以下代码编写了一个 Main 类:
...
int []test = new int[Integer.MAX_VALUE];
...
它包含以下内容:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
为此需要多少堆大小?我使用以下命令增加了 Eclipse 大小,但仍然失败:
-Xms4g
-Xmx4g
最佳答案
int
在 Java 中是 32 位。您需要超过 8G 的内存来存储该数组 (4*(231-1))。
关于java.lang.OutOfMemoryError - new int[Integer.MAX_VALUE];,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8231365/