Troubleshooting Exceptions: System.OutOfMemoryException
An OutOfMemoryException exception is thrown when an attempt to allocate memory fails.
Excessive managed memory usage is commonly caused by:
Reading large data sets into memory.
Creating excessive cache entries.
Uploading or downloading large files.
Excessive use of regular expressions or strings while parsing files.
Excessive view state.
Too much data in session state or too many sessions.
This exception may be thrown with an additional message, "Not enough storage is available to complete this operation," when invoking a method on a COM object that returns a user-defined type that contains a safe array (an array of non-fixed size). This is because the .NET Framework cannot marshal a structure field with a safe array type.