-
June 29th, 2009, 08:07 AM
#1
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?
Am I missing something about the XmlDocument class I should know?
-
June 29th, 2009, 08:24 AM
#2
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...?
-
June 29th, 2009, 08:26 AM
#3
Re: how to release the resources of XmlDocument
The code of my webpage
Code:
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e) {
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("data/reports/lastmonth/publisher.xml")); //the 10mb xml-file
}
protected void Button2_Click(object sender, EventArgs e) {
GC.Collect();
}
}
after some closer looking, the memory even increases almost 100mb for the first call!!
-
June 29th, 2009, 09:14 AM
#4
Re: how to release the resources of XmlDocument
The Garbage Collector runs when it sees fit. It does not run at specific times and does not run after a method is called....
http://msdn.microsoft.com/en-us/library/0xy59wtx.aspx
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.
-
June 29th, 2009, 09:19 AM
#5
Re: how to release the resources of XmlDocument
So I just should wait untill the memory usage decreases after the GC has decided the collect?
To come back on what Grofit said:
it sounds like memory leaks (inside the XDocument)
Is this possible?
And why increases the memory with 100MB for a 10MB file?
-
June 29th, 2009, 09:46 AM
#6
Re: how to release the resources of XmlDocument
Originally Posted by dannystommen
So I just should wait untill the memory usage decreases after the GC has decided the collect?
To come back on what Grofit said:
Is this possible?
And why increases the memory with 100MB for a 10MB file?
Why would you "wait" for it? Are you running code that depends on what the memory usage is?
-
June 29th, 2009, 09:49 AM
#7
Re: how to release the resources of XmlDocument
Originally Posted by eclipsed4utoo
Why would you "wait" for it? Are you running code that depends on what the memory usage is?
What I meant with that is that I don't need to perform any action and that the memory usage will decrease by itself?
-
June 29th, 2009, 12:26 PM
#8
Re: how to release the resources of XmlDocument
Originally Posted by dannystommen
What I meant with that is that I don't need to perform any action and that the memory usage will decrease by itself?
correct. that's what the GC is there for.
-
June 30th, 2009, 01:57 AM
#9
Re: how to release the resources of XmlDocument
I noticed that the memory usage has decreased back to about 100MB after the night, so looks like the GC does it job after all.
But still, how is het possible that opening 3 files of 10MB increases the memory usage from 100MB tot about 500MB?
-
April 18th, 2013, 05:05 AM
#10
Re: how to release the resources of XmlDocument
I guess it is not correct to compare the physical size of a file on disk to the memory required to open the file using some other process
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|