OutOfMemoryException only in Release mode when compiled with VS2010?
My program generates OutOfMemoryExcetion
only in Release mode, compiling with VS2010 C# compiler. The operation that it was performing when the crash occurred was instantiating 1600 jagged arrays, and it broke when at the 207th of the simplified version of the loop below:
Double[][] arr = new Double[1600][];
int i = 0;
while (i < 1600)
{
arr[i] = new Double[1000000];
i++;
}
Basically, just this part of code would generate ~ 11.9 GB, considering that a Double consumes 8 bytes. I don't have that amount of RAM, but in another question where I asked what happens when the RAM is over, they answered me that the CLR creates a swap memory, though it can only address a well defined amount of memory.
When I compile my program in DEBUG mode, it doesn't throw the OutOfMemoryException
, instead, it allocates a lot of memory and keep the program running... I didn't have enough patience to check if the program would run smooth, though slowly, until the end, because it was taking too long.
So:
Assuming you created your project in Visual Studio 2010, its platform target would have defaulted to x86, ie, a 32-bit program. I'm assuming you changed this to x64 already, or you never would have been able to allocate more than 2GB of address space.
My guess is that you just went to project properties > Build tab, and changed "Platform target". The thing is, if that's all you did, that would only affect your Debug build configuration, because the "Configuration" filter at the top of the screen defaults to "Active (Debug)".
Change that filter box to "Release" to see your release build settings. You'll need to change "Platform target" to "x64" here as well.
链接地址: http://www.djcxy.com/p/27962.html