Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Arrays.java:3209)
at java.lang.String.<init>(String.java:216)
at java.io.BufferedReader.readLine(BufferedReader.java:331)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at fileCompare.main(fileCompare.java:54)
Java Result: 1
如果程序本身没有问题,如内存溢出等,那解决办法是增加heap size。
Netbean用户:
http://developers.sun.com/docs/javacaps/installing/jcapsinstall.inst_increase_heap_size_t.html
http://wiki.netbeans.org/FaqSettingHeapSize
http://performance.netbeans.org/howto/jvmswitches/index.html
Two JVM options are often used to tune JVM heap size:
-Xmx
for maximum heap size, and
-Xms
for initial heap size. Here are some common mistakes I have seen when using them:
-
Missing
m, M, g
or
G
at the end (they are case insensitive). For example,
java -Xmx128 BigApp
java.lang.OutOfMemoryError: Java heap space
The correct command should be:
java -Xmx128m BigApp
. To be precise,
-Xmx128
is a valid setting for very small apps, like HelloWorld. But in real life, I guess you really mean
-Xmx128m
-
Extra space in JVM options, or incorrectly use =. For example,
java -Xmx 128m BigApp
Invalid maximum heap size: -Xmx
Could not create the Java virtual machine.
java -Xmx=512m HelloWorld
Invalid maximum heap size: -Xmx=512m
Could not create the Java virtual machine.
The correct command should be
java -Xmx128m BigApp
, with no whitespace nor =. -X options are different than -Dkey=value system properties, where = is used. -
Only setting