Search code examples
c#out-of-memorygcallowverylargeobjects

Possible drawbacks of gcAllowVeryLargeObjects?


After several outOfMemory exceptions, I enabled "gcAllowVeryLargeObjects", it works perfectly fine. I am now wondering why it is not a default option in C# (on a 64-bit platform).

Is it for pure compatibility reasons ? Or am I missing a major drawback of gcAllowVeryLargeObjects ?


Solution

  • MSDN says:

    Before enabling this feature, ensure that your application does not include unsafe code that assumes that all arrays are smaller than 2 GB in size. For example, unsafe code that uses arrays as buffers might be susceptible to buffer overruns if it is written on the assumption that arrays will not exceed 2 GB.

    So as long you are not using unsafe code, there are no drawbacks.