What is causing the asp.net out of memory exception

I have a simple asp.net site that reads a large text file into memory and does some processing. Below is the code that raises the OOM exception. After reading about 350K lines I am getting this error. Each line has an average of 1,000 characters. Is there a memory limit on IIS or ASP.Net sites? My server still has a lot of physical memory left. Thank.

List<string> geos = new List<string>();
using (StreamReader geoReader = new StreamReader(File.OpenRead("file.txt")))
{
    while (geoReader.EndOfStream == false)
    {
        try
        {
            geos.Add(geoReader.ReadLine());
        }
        catch (Exception ex) { }
    }
}

      

+3


source to share


2 answers


Most likely your workflow is set to 32 bit (x86). In this case, you will end up in the OOM with at least about 2GB of allocated objects, but most likely much earlier.

If you really need to load more than letting 1GB of an object in memory, consider running your code in a 64-bit process.



Note: above, assuming you are actually running out of memory, and not something like trying to make a 2GB + allocation right away - which will throw OOM by default (the latter .Net allows larger allocations as far as I remember).

+2


source


I did some searches on msdn and I found several things that might help you.

There are a few things to consider: first, the likelihood of an OutOfMemoryException starts to increase sharply when "Process \ Virtual Bytes" is within 600 MB of virtual address space (usually 2 GB), and second, tests have shown that " Process \ Virtual Bytes "is often larger than" Process \ Private Bytes "by no more than 600 MB. This difference is in part due to the MEM_RESERVE regions maintained by the GC, allowing it to quickly allocate more memory when needed. Collectively, this means that when "Process \ Private Bytes" exceeds 800 MB, the chance of an OutOfMemoryException being thrown is increased. In this example, the device has 4 GB of physical memory, so you need to set the memory limit to 20% to avoid memory issues.You can experiment with these numbers to make the most of your computer's memory, but if you want to play safely, the numbers in this example will work. To summarize, set the memory limit to less than 60% of physical memory, or 800 MB. Since v1.1 supports 3GB virtual address space, if you add / 3GB in boot.ini you can safely use 1800MB instead of 800MB as the upper boundyou can safely use 1800 MB instead of 800 MB as your upper boundyou can safely use 1800 MB instead of 800 MB as your upper bound



http://msdn.microsoft.com/en-us/library/ms972959

Another possible cause might be the missing .NET Framework 1.1 Service Pack 1. My guess is that there is a higher chance of in-memory exceptions without installing the service pack.

+1


source







All Articles