我使用Out Of Memory help from sun's site。凡有引述如何模擬內存不足:請求的數組大小超過VM限制
Out Of Memory : Requested array size exceeds VM limit
This indicates that the application attempted to allocate an array that is larger than the heap size. For example, if an application tries to allocate an array of 512MB but the maximum heap size is 256MB, then this error will be thrown. In most cases the problem is likely to be either that the heap size is too small or that a bug results in the application attempting to create an array whose size is calculated to be incorrectly huge.
我試圖通過
import java.util.ArrayList;
import java.util.List;
public class JavaTest {
public static void main(String[] args){
long[] ll = new long[64*1024*1024];
}
}
我的機器上用
javac *.java;java -Xmx256m JavaTest
但上面的線是生產
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at JavaTest.main(JavaTest.java:7)
模擬這個是什麼我錯過了嗎?
更新: 我的Java版本是
$java -version java version "1.6.0_15" Java(TM) SE Runtime Environment (build 1.6.0_15-b03) Java HotSpot(TM) Server VM (build 14.1-b02, mixed mode)
謝謝。這也適用於我。但爲什麼我的代碼沒有工作得更早? – DKSRathore 2009-12-10 13:01:01
好的。所以我的系統在1024 * 1024 * 1024-2到Integer.MAX_VALUE – DKSRathore 2009-12-10 13:10:32
@Adrian的範圍內產生這個異常,我怎麼知道我的VM限制? – DKSRathore 2009-12-10 13:11:33