Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / August 2007

Tip: Looking for answers? Try searching our database.

virtual memory leak? in asp.net app - OutOfMemory exception

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 27 Jun 2007 17:44 GMT
Hello,

I have an ASP.Net app pulling a large XML stream (50 MB) and loading into an
XmlDocument object.  Doing so seems to allocate several hundred MBs of
virtual memory (Seen as "virtual bytes" in perfmon).  This behavior seems to
happen in the XmlDocument.Load() method.

When the XmlDocument object goes out of scope, the application releases the
"working set" after a period of time, or immediately if I call GC.Collect(),
but the allocated "virtual bytes" remain.

Loading the same XML stream again seems to re-use the allocated virtual
memory, but loading a different XML stream allocates even more virtual
memory.  Eventually the application throws an OutOfMemory exception.

Why is the app not releasing the virtual memory as it reaches is memory
limits?

How can I tell the application to release the virtual memory?

Is there something about the XmlDocument object I should know?

Any commands in WinDbg that might help me see what is in virtual memory?

Thanks,
Mike
Mattias Sjögren - 27 Jun 2007 19:44 GMT
>Is there something about the XmlDocument object I should know?

That it isn't suitable for loading huge documents. have you considered
using XmlTextReader instead?

>Any commands in WinDbg that might help me see what is in virtual memory?

With the SOS.dll extensions you can look at pretty much anything you
want on the managed heap.

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Ben Voigt [C++ MVP] - 28 Jun 2007 05:10 GMT
> Hello,
>
[quoted text clipped - 19 lines]
>
> How can I tell the application to release the virtual memory?

Restart the process.  I don't believe the Common Language Runtime ever gives
memory back to Windows.

> Is there something about the XmlDocument object I should know?
>
> Any commands in WinDbg that might help me see what is in virtual memory?
>
> Thanks,
> Mike
Mike - 29 Jun 2007 18:44 GMT
> Restart the process.  I don't believe the Common Language Runtime ever gives
> memory back to Windows.

Ben, Thanks for your reply.

I'm shocked that the CLR would not release memory back to Windows.  Do you
have a citation you can share that would support this?  And, if this is an
intentional design, justification for it?

Mike
Willy Denoyette [MVP] - 30 Jun 2007 09:07 GMT
>> Restart the process.  I don't believe the Common Language Runtime ever
>> gives
[quoted text clipped - 7 lines]
>
> Mike

The CLR returns the excess memory to the OS whenever the OS asks the process
to trim it working set. However, this is not your problem. Each process in
Windows 32 bit can consume a maximum of 2GB of virtual memory space for data
and code, whenever you exceed this amount you will get an OOM exception. The
asp.net worker process however, restricts its virtual address space to a
(configurable) value which is much lower than this 2GB. By default, only 60%
of available system memory can ever be used as VAD space for the worker
process. So, for a system with 1GB of memory, that means that only 600MB can
be used by the asp.net worker process. If you want to allocate more than
this, you will have to increase the "memoryLimit" in your system.web config
file, but *much* better is to follow Mattias suggestion and use
XmlTextReader instead of XmlDocument.

Willy.
Ben Voigt [C++ MVP] - 02 Aug 2007 18:39 GMT
>> Restart the process.  I don't believe the Common Language Runtime ever
>> gives
[quoted text clipped - 5 lines]
> have a citation you can share that would support this?  And, if this is an
> intentional design, justification for it?

Just that very few applications do.  Here is a quote from MSDN:

"The HeapCreate function creates a private heap object from which the
calling process can allocate memory blocks by using the HeapAlloc function.
HeapCreate specifies both an initial size and a maximum size for the heap.
The initial size determines the number of committed, read/write pages
initially allocated for the heap. The maximum size determines the total
number of reserved pages. These pages create a contiguous block in the
virtual address space of a process into which the heap can grow. Additional
pages are automatically committed from this reserved space if requests by
HeapAlloc exceed the current size of committed pages, assuming that the
physical storage for it is available. Once the pages are committed, they are
not decommitted until the process is terminated or until the heap is
destroyed by calling the HeapDestroy function."

I don't know if the CLR uses HeapCreate or not, but almost all Windows
programs do.

> Mike

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.