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:
- what did happen in Release mode that didn't in Debug mode, causing the program to throw an Exception there?
- considering I really need to store that amount of memory, because it is the data generated by some scientific computations, what are your advices to handle this problem? (I'm considering processing the generated data during the calculations, though it would take a little more time during the calculations itself, instead of generating a lot of data and then processing it...)