Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET System.OutOfMemoryException

This is Windows server 2008 R2, 64 bit, 32gb RAM, I think its running IIS 7.5. We have set the application pool to use 4 worker process.

This is a ASP.NET 4 application but running in 32 bit compatability mode.

We are getting oSystem.OutOfMemoryException when the memory usage crosses more than 650-700MB/worker process.

I thought that it should be able to handle upto 2gb or atleast 1.5 gb with no issues?

Another thing, why does it not recycle the worker process when there is a System.OutOfMemoryException?

update: This application works perfectly fine on a 64bit windows server 2003 with IIS6.0. I have seen the max memory usage of it being around 700mb/worker process.

Update: The reason for high memory usage is XML processing using DOM. We are going to start work to fix that, but thats a long term plan. I just find it weird that it cannot go higher than 650 mb.

like image 246
krprasad Avatar asked Feb 18 '13 22:02

krprasad


People also ask

What is System OutOfMemoryException?

When data structures or data sets that reside in memory become so large that the common language runtime is unable to allocate enough contiguous memory for them, an OutOfMemoryException exception results.

How do you avoid OutOfMemoryException?

Well, according to the topic of the question, best way to avoid out of memory exception would be not to create objects that fill in that memory. Then you can calculate the length of your queue based on estimate of one object memory capacity. Another way would be to check for memory size in each worker thread.

How does Outofmemory handle exception in Android?

Check that the image size is smaller than the available memory before attempting to load it. So the most efficient way to handle OutOfMemoryException is to architecture your application in such a way that it never attempts to load lots of data into memory in order to avoid the exception.


2 Answers

More common reason to get System.OutOfMemoryException is due to memory fragmentation - there is no large enough continuous space in memory. You should install a memory profiler to verify that - then you can also try to find out which objects take up the memory.

If possible, you might want to test .NET 4.5 - Microsoft has made changes to the Garbage Collector so that LOH is automatically defragmented for server applications (such as IIS): http://blogs.msdn.com/b/dotnet/archive/2011/10/04/large-object-heap-improvements-in-net-4-5.aspx

like image 68
Knaģis Avatar answered Oct 19 '22 23:10

Knaģis


Have you configured your server to handle server garbage collection properly? For asp 4.5 the setting is under the runtime node in the Aspnet.config file

<performanceScenario value="HighDensityWebHosting">
like image 25
Adawg Avatar answered Oct 20 '22 00:10

Adawg