Any variable goes out of scope if you don't keep references to it (for
example in some global cache).
IDisposable is not implemented in the XmlDocument as its resources are pure
..NET object and references that are automatically freed by the garbage
collector.
You don't even need to set it to null before exiting the method.
Can you show us the full code that "leaks"?
--
Daniel Cazzulino [MVP XML]
Clarius Consulting SA
http://weblogs.asp.net/cazzu http://aspnet2.com
"Matthew Wieder" <De*********@SatoriGroupInc.com> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...
When I attempt to compile the code you suggested, I get the error that
"Cannot implicitly convert type 'System.Xml.XmlDocument' to
'System.IDisposable'" If XmlDocument does not implement IDisposable,
then perhaps there is a larger issue here that the XmlDocument never
goes out of scope?
thanks,
-Matthew
Kevin Yu [MSFT] wrote: Hi
First of all, I would like to confirm my understanding of your issue.
From your description, I understand that memory of the XmlDocument was not
released after using in your app. If there is any misunderstanding,
please feel free to let me know.
As far as I know, the memory has to be released automatically when the
object reference is out of scope. The Garbage Collection of .NET
framework's CLR will do this for us. If the memeory is not released,
please try to use the using statement in C#, so that we can make sure that the
memeory is enforced to be released when out of scope. Here is an
example:
public void Clean(string strCleanXMLPath)
{
using(XmlDocument xmlDoc = new XmlDocument())
{
xmlDoc.Load(strCleanXMLPath);
//do some work here on the xmlDoc
XmlTextWriter wrtr = new XmlTextWriter(strCleanXMLPathEncoding.UTF8);
wrtr.Formatting = Formatting.Indented;
xmlDoc.WriteTo(wrtr);
wrtr.Close();
xmlDoc = null;
}
}
HTH. If anything is unclear, please feel free to reply to the post.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.679 / Virus Database: 441 - Release Date: 07/05/2004