這是我的代碼:這個C#程序爲什麼會在內存爲24GB的64位計算機中耗盡內存?
public class Class1 { public int[][] binArray; public Class1() { binArray = new int[1000][]; for (int i = 0; i < 1000; i++) { binArray[i] = new int[61608]; } } }
class Program
{
static void Main(string[] args)
{
Class1 c1 = new Class1();
Class1 c2 = new Class1();
Class1 c3 = new Class1();
Class1 c4 = new Class1();
Class1 c5 = new Class1();
Class1 c6 = new Class1();
Class1 c7 = new Class1(); // Memory will run out at about this point
Class1 c8 = new Class1();
Class1 c9 = new Class1();
Class1 c0 = new Class1();
Console.WriteLine();
}
}
Class1的用於存儲陣列,我認爲這將得到61608個* 4字節足夠的內存碎片的內存機器的24GB,爲什麼當我初始化第七課時,它仍然會拋出一個out of memory exception
?
我也在8GB和12GB內存的64位機器上試用這個,結果也一樣。 – user2108826 2013-02-25 21:02:01
您是否在構建時定位到x64? – Saggio 2013-02-25 21:04:37
您是否編譯並運行AnyCPU,x86或x64? – 2013-02-25 21:04:48