views:

80

answers:

3

Hello,

I'm aware that .NET doesn't use complete physical memory availabe. I've encountered a System.OutOfMemoryException while the physical memory usage as only 79%. I've run my system until 92% of physical memory usage.

You can see screenshot here: http://a.imagehost.org/0655/CaptureOOM.gif alt text

How do I tell .NET to use more memory?

I also want to know, is this exception because of .NET has insufficient memory or .NET has memory but not for this application?

+2  A: 

OutOfMemoryException has nothing to do with physical memory. It is because you didn't have a large enough block of contiguous virtual memory. Sometimes .NET will even throw an OutOfMemoryException if you ran out of file handles or some other limited resource.

Mark Byers
A: 

There really isnt an option to modify this its controlled by the .NET Environment and has its own Garbage Collection to handle memory management.

If you have objects you want to finalize and dispose you can force a GC with

GC.Collect(); GC.WaitForPendingFinalizers();

Some notes

Allocated the object in a different method than the Main method. This is because if the allocated object in the Main method then called GC.Collect in the same method, the object would technically still be associated with running code and would therefore not be eligible for collection.

The GC.Collect method is designed not to control specific object destruction, but to allow for the forcing of collection for all of unused objects. Therefore, it's a very expensive operation and should only be used in cases where you want/need to force global collection. For situations where you want to force the finalization of a specific object, you should implement the Dispose pattern.

Hopefully this helps.

Gary Steven
A: 

Are you running this in a virtual machine? Is there enough virtual memory space allocated? How large is the allocation you are trying to accomplish?

You really need to do more forensic debugging to figure out exactly what is failing and the parameters of the function.

Mystere Man