views:

1009

answers:

3

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 'System.OutOfMemoryException' was thrown.
at
OpenAccessRuntime.DataObjects.PersistenceManagerFactoryBase.
CreatePersistenceMangerImp(StorageManger sm)
at
....
+1  A: 

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.
James Black
there is no problem in the actual import which is from the csv file to the database. The problem is adding new records from one row in the csv file to different tables their are almost 30 function calls in one loop. But what are the possible issues is it the memory or the code?
Ravi
If you have that complicated of an import what you may want to do is to see if one of the calls is the culprit by commenting out some and just keep commenting different ones out until you find out. I expect it is your code as it sounds like your program is getting very large. Have you thought about using LINQ, so you only read in and process one line at a time?
James Black
A: 

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/

Chris
could this really be a memory issue? because it just has 400++ records? others have problems in the 100,000++ records
Ravi
+1  A: 

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

marc_s
nice reply...the issue is that their are more than 10 requests for one record...and when the memory reaches 1.4 GB it collapses with the System Out of Memory Exception..
Ravi
OK, so it's not a single request that gobbles up 1.4 GB - that's what I seem to understand from your question....The solution is still the same: self-hosting.
marc_s