开发者

System.OutOfMemoryException on WCF Web Service

开发者 https://www.devze.com 2022-12-08 22:50 出处:网络
I struggle on a System.OutOfMemoryException when performing an import process where a lot of objects are being created.

I struggle on a System.OutOfMemoryException when performing an import process where a lot of objects are being created.

The effect is that the ASPNET_WP.EXE blows up to 1.4 GB and the exception will be thrown.

I already tried to implement IDisposable and calling the Garbage Collector (GC.Collect()) in that responsible functions, but no effect.

The Server is a QuadCore (C2Q) with 4 GB RAM. Even if there is more RAM free than 1,4 GB the exception is always thrown when the aspnet_wp.exe reaches 1.4 GB.

What can I do to avoid these OutOfMemory issues?

The exact exception message is:

System.OutOfMemoryException: Exception of type 'S开发者_StackOverflowystem.OutOfMemoryException' was thrown.
at
OpenAccessRuntime.DataObjects.PersistenceManagerFactoryBase.
CreatePersistenceMangerImp(StorageManger sm)
at
....


One word: self-hosting.

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

Quick question though: how is your server going to handle 10 simultaneous requests if handling each request will use up 1.4 GB of memory....

Are you trying to pass back files or something? In that case, you should check out WCF streaming which allows you to substantially reduce the size of buffer memory needed on the server.

Marc


Can you do your import in pieces, rather than creating lots of objects quickly and disposing of them.

You may want to explain more about what is going on, how your are processing the import.

For example, can you fully process and save each object, then do another object?

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

I would look at two things.

  1. Can you change your algorithm to prevent this.
  2. Get more information as to why this is happening.


Keep in mind that you don't get access to all memory if you're running in asp.net, it'll only allow you 2gigs with a standard configuration. Maybe you should farm this out to a windows service, or a console app.

See here: "Fact: In a standard setup your worker process always have 2GB Virtual memory available (no matter if you have 1, 2 or 4GB physical memory in the machine)."

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

0

精彩评论

暂无评论...
验证码 换一张
取 消