.NET OutOfMemoryException

P

Peter Aberline

Hi all,

We have written a C # .NET application and we're
encountering memory problems in the form of
System.OutOfMemoryException.

Our application creates many thousands of objects in a
temporary in memory store, which uses a lot of runtime
memory. Not an ideal situation, but an acceptable short
term solution given our project constraints.

This works well for almost all size data inputs to the
software. However, on the very largest input datasets the
number of objects in the temporary store pushes the amount
of memory used on our test machine to it's physical limit.
After this point we would expect it to go into virtual
memory, but instead a System.OutOfMemoryException is
thrown, even though there is 4Gb of virtual memory
available. Other programs, such as Notepad, can use all
the virtual memory should they need to.

There should be no contention for virtual memory as the
software is running from an 'exe' on the c: drive and all
of our paging is on a separate dedicated disk (the d:
drive).

Can anyone suggest a way of ensuring that our .NET
application can access virtual/paging memory?

many thanks,
Peter
 
A

Andy Fish

I'm sure that there is nothing in .net which stops it from using VM
properly. You could try writing a test harness that just allocates loads of
memory to verify this.

Here's the only thing I can think of, which is something I have seen before
on a (non-dotnet app) that used a lot of memory:

If you allocate and free a lot of memory, It is possible you could fill the
address space up, so although there is virtual memory available, the 32-bit
address space is does not have big enough gaps to allocate the memory range
you need.

not sure how to get round this in .net though :(
 
T

Tian Min Huang

Hi Peter,

Thanks for your post. I'd like to share the following information with you:

1. Under .NET environment, the CLR requires that all resources be allocated
from a area of memory called managed heap. It is the common language
runtime's garbage collector that manages the allocation and release of
memory for a .NET application. We do not have much control over managed
heap and it will be automatically expand as you use more memory. Please
refer to the following article for detailed information on GC:

Garbage Collection: Automatic Memory Management in the Microsoft .NET
Framework
http://msdn.microsoft.com/msdnmag/issues/1100/GCI/default.aspx

Garbage Collection Part 2: Automatic Memory Management in the Microsoft
NET Framework
http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx

2. I suggest you to use .NET Memory Profiler to check the memory usage of
both managed heap and native memory in your process.

NET Memory Profiler
http://www.scitech.se/memprofiler/

Please keep in mind that the 4GB process's virtual address space consists
of 2 GB user-mode, and 2 GB reserved as system memory. That is, 2GB
user-mode virtual address space can be used by an application. If your
system is Windows 2000 Advanced Server, Windows 2000 Data Center, or
Windows NT 4.0 Enterprise, you can increase it to 3GB by appending the /3GB
switch to the desired entry in your system's BOOT.INI file and check
whether or not the problem still exists.

3. In addition, you may consider creating unmanaged components and interop
with your managed application.

Interoperating with Unmanaged Code
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconinteroperatingwithunmanagedcode.asp?frame=true

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top