Fixing System.OutOfMemoryException in WCF Web Service

I am trying to use System.OutOfMemoryException while doing an import process that creates a lot of objects.

The effect is that ASPNET_WP.EXE bloats to 1.4GB and an exception will be thrown.

I've already tried to implement IDisposable and call the garbage collector (GC.Collect ()) in these responsible functions, but no effect.

The server is a QuadCore (C2Q) with 4 GB of RAM. Even if there is more than 1.4 GB of RAM, an exception is always thrown when aspnet_wp.exe reaches 1.4 GB.

What can I do to avoid these OutOfMemory problems?

The exact error message:

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at
OpenAccessRuntime.DataObjects.PersistenceManagerFactoryBase.
CreatePersistenceMangerImp(StorageManger sm)
at
....

      

+2


source to share


3 answers


Can you do your import in chunks rather than quickly creating lots of objects and getting rid of them.

You might want to explain what's going on, how to handle imports.

For example, can you completely process and save each object and then make another object?



You might want to get a memory profiler. Here are some open source C # profiles: http://csharp-source.net/open-source/profilers

I would look at two things.

  • Can you change your algorithm to prevent this.
  • Get more information on why this is happening.
+1


source


One word: self-hosting .

IIS has limitations and warts when it comes to memory handling, and if your WCF service really needs to use more than 1.4GB of memory on the server, then you need to host that WCF service yourself, in a console application, NT Service, Winforms application - which whatever method you choose.

Quick question: how would your server handle 10 concurrent requests if processing each request would use 1.4GB of memory ....



Are you trying to transfer files or something else? In this case, you should inspect the WCF streams , which can significantly reduce the size of the buffer memory required on the server.

Mark

+2


source


Keep in mind that you are not accessing all memory if you are running in asp.net, this will only allow you 2gigs with a standard configuration. Perhaps you should use this for a windows service or console application.

See here: "Fact: Under standard setup, your workflow always has 2 GB of virtual memory available (regardless of whether you have 1, 2, or 4 GB of physical memory in the machine).

http://jesperen.wordpress.com/2007/05/23/understanding-aspnet-memory/

0


source







All Articles