I want to see the System.OutOfMemoryException and the memory consumed in the task manager, when the app is built against x64. There are two drop-downs in the Build tab in the app properties: “Platform target” and “Platform”, both are set to x64.
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<long> lst = new List<long>();
while (true)
{
lst.Add(long.MaxValue);
}
}
}
}
It is indeed showing OutOfMemoryException…but when it stops, the task manager is showing a number like 1587443K which is 1.5GB which would I expect if it was built against x86.
Yes, the operating system is 64bit.
Am I forgetting something else?
Yes – in .NET 4, there was still a 2GB-per-object limit. (You could use much more memory, but not in a single object.) I suspect your list needs to reallocate its internal buffer, requiring ~3GB in a single array.
You may be pleased to hear that .NET 4.5 supports larger objects if you set the
<gcAllowVeryLargeObjects>configuration parameter.