Why does the exception "java.lang.OutOfMemoryError: Java heap space" keep appearing even after changing the -xmx VM option?

Why does the exception "java.lang.OutOfMemoryError: Java heap space" keep appearing even after changing the -xmx VM option?

我在 Mac 上使用 64 位 OS,内存为 8GB。我需要为用 Java 编写的程序中的一些字节数组分配 2.9GB(我只是声明它们)。由于默认情况下您不能为 运行 宁一个 java 项目使用超过 1GB 的堆 space,如果您的程序需要更多,您需要在 VM 选项中指定。我在使用 IntelliJ Idea,所以我通过 Help -> Edit Custom VM Options 然后更改 -xmx 字段来做到这一点。但是无论我分配多少 MB,程序都不能 运行 由于这个异常:Exception in thread "main" java.lang.OutOfMemoryError: Java heap space,就好像我没有在 VM 选项中更改任何内容一样。 运行运行程序时,PC 有足够的可用 RAM 来包含 2.9GB 的数组。

Help -> Edit Custom VM Options 是为 IDEA 本身而不是你的程序设置的。在 Run -> Edit Configurations.. -> your application -> VM options 中设置 -Xmx