ASP.NET System.OutOfMemoryException
Solution 1
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
Solution 2
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">
Solution 3
Did you check the max. allocated memory, and not just the currently allocated memory when you looked into taskmanager ?
Because the max. allocated memory is the memory it ACTUALLY reserves and therefore uses.
A common cause for such an exception would be a large DataTable displayed in a unpaged datagrid.
krprasad
Updated on June 25, 2022Comments
-
krprasad about 2 years
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.
-
krprasad over 11 yearsthe server itself has 32gb ram, and I have never seen it consume more than 6gb. So not sure why the memory would be fragmented?
-
Knaģis over 11 yearsYour managed process heap is fragmented, not the server memory. Just assume that .NET VM will allocate 2Gb large block and work within it...
-
krprasad over 11 yearsI dont see any option where I can look up the max allocated memory to a process in TaskManager, anybody?
-
krprasad over 11 yearsthis is a tough one, I cant think of how I am going to take care of memory fragmentation, in a managed application. That is done by garbage collection, right?
-
Knaģis over 11 yearsYou have to identify what objects are the ones that are taking up the memory. Most probably those are some that reside in Large Object Heap (>85kb, since those are never moved to defragment). You might find some that you can clean up earlier in the process, reuse (create a pool etc.) or you might be forced to manually call
GC.Collect
at some point in your application (GC collects large objects much less often than small ones). -
Knaģis over 11 yearsAlso you might test if installing .NET 4.5 helps to mitigate the problem since there have been changes in GC related to this: blogs.msdn.com/b/dotnet/archive/2011/10/04/…
-
Knaģis over 11 yearsUse Commit Size : windows.microsoft.com/en-US/windows-vista/…
-
Kiquenet over 8 yearsMore information asp.net 3.5 vs asp.net 4.0 My case about OutOfMemoryException is not memory problem, I don't know yet stackoverflow.com/questions/33436607/… Maybe configuration IIS, Pool, web.config issues ?
-
Kiquenet over 8 yearsGood patterns and practices about performanceScenario asp.net/aspnet/overview/aspnet-and-visual-studio-2012/… ? News in APS.NET 4.5, yeah. I'm newbie and confused about good patterns and practices using performanceScenario in ASP.NET 4.5, my website I think is slow.