I am not sure, but the reason may be the following:
Your C # application runs in the .NET runtime, which, when possible, clears heap memory using the garbage collector.
This method has a side effect for fragmenting your heap memory. So, for example, you can have 100 MB allocated, with 40% available for new variables that are fragmented in smaller pieces of max. 5 MB
In this situation, when you allocate a new 10 MB array, the .NET virtual machine cannot allocate it even if it has 40 MB for free.
To solve the problem, move your available heap memory to 110 MB (at best) and allocate a new 10 MB for the new byte array.
Also see: http://msdn.microsoft.com/en-us/magazine/dd882521.aspx#id0400035
source share