尝试增加 jvm 内存时,您可以将 Xmx 设置为最大数量吗?
有最大值吗?您可以将 Xmx 设置为的大小?我将它设置为 1024m 并且 Eclipse 可以正常打开.当我将其设置为 1024 以上时,eclipse 无法打开,并且出现错误jvm 已终止.退出代码=-1"...
Is there a max. size you can set Xmx to? I set it to 1024m and eclipse opens ok. When I set it above 1024, eclipse doesn't open and I get the error "jvm terminated. Exit code=-1"...
我这样做是因为我不断收到java.lang.OutOfMemoryError: Java heap space".我正在读取一个 35.5Mb 的 .txt 文件,当它只是使用while((line = reader.readLine()) != null)
"循环读取文件时会发生此错误.我原以为1024mb就足够了.谁能帮帮我?
I was doing this because I keep getting an "java.lang.OutOfMemoryError: Java heap space". I am reading in a 35.5Mb .txt file and this error occurs when it's just reading in the file using the "while((line = reader.readLine()) != null)
" loop. I would have thought that 1024mb would have been enough. Can anyone help me?
推荐答案
是的,有一个最大值,但它取决于系统.试试看,加倍直到达到极限,然后向下搜索.至少在 Linux 上使用 Sun JRE 1.6 时,您会得到有趣的错误消息(如果不总是提供信息)(peregrino 是运行 32 位 ubuntu 且具有 2G RAM 且无交换的上网本):
Yes, there is a maximum, but it's system dependent. Try it and see, doubling until you hit a limit then searching down. At least with Sun JRE 1.6 on linux you get interesting if not always informative error messages (peregrino is netbook running 32 bit ubuntu with 2G RAM and no swap):
peregrino:$ java -Xmx4096M -cp bin WheelPrimes
Invalid maximum heap size: -Xmx4096M
The specified size exceeds the maximum representable size.
Could not create the Java virtual machine.
peregrino:$ java -Xmx4095M -cp bin WheelPrimes
Error occurred during initialization of VM
Incompatible minimum and maximum heap sizes specified
peregrino:$ java -Xmx4092M -cp bin WheelPrimes
Error occurred during initialization of VM
The size of the object heap + VM data exceeds the maximum representable size
peregrino:$ java -Xmx4000M -cp bin WheelPrimes
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
(experiment reducing from 4000M until)
peregrino:$ java -Xmx2686M -cp bin WheelPrimes
(normal execution)
大多数都是不言自明的,除了 -Xmx4095M 这很奇怪(可能是有符号/无符号比较?),它声称在没有交换的 2GB 机器上保留 2686M.但它确实暗示了 32 位 VM 的最大大小是 4G 而不是 2G,如果操作系统允许你处理那么多的话.
Most are self explanatory, except -Xmx4095M which is rather odd (maybe a signed/unsigned comparison?), and that it claims to reserve 2686M on a 2GB machine with no swap. But it does hint that the maximum size is 4G not 2G for a 32 bit VM, if the OS allows you to address that much.
相关文章