If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

how to release the resources of XmlDocument

When I open an xml file using the XmlDocument.Load function, the memory usage increases a lot.

The file I'm opening is size of 10MB. When I open this file in a WinApp, the momory usage increases with about 25mb (the file is only 10MB). I have 3 versions of this file, when I open them all 3 (a few times), the memory is increases about 75MB. In my website it even increases from 100MB to 450-500MB.

Looks like the GC does not collect them. The XmlDocument objects I'm using, are all local variables, thus I know for sure that there is no more reference to the object after the method is executed.

When I'm correctly informed, the GC collects after the method is executed and the local variables aren't in use any more. But when I force the GC using GC.Collect(), the memory usage is decreased a bit (back to 200MB in website), but never gets back to the original 100MB.
I also know that the GC.Collect method shouldn't be used, thus I would like to know if there is any other option that releases the resource of the XmlDocument class?

Re: how to release the resources of XmlDocument

Im currently doing some stuff with XDocument on hosting so it would be nice to find out how you solve this one... it sounds like memory leaks (inside the XDocument) or the data is still in use somewhere in your app, but i dont really know that much about it... Could you post a snippit of your code?

It could *possibly* be down to the file handle not being freed up or something...?

Re: how to release the resources of XmlDocument

The .NET Framework's garbage collector manages the allocation and release of memory for your application. Each time you use the newoperator to create an object, the runtime allocates memory for the object from the managed heap. As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. However, memory is not infinite. Eventually the garbage collector must perform a collection in order to free some memory. The garbage collector's optimizing engine determines the best time to perform a collection, based upon the allocations being made. When the garbage collector performs a collection, it checks for objects in the managed heap that are no longer being used by the application and performs the necessary operations to reclaim their memory.