Mark Rae <ma**@markNOSPAMrae.netwrote:
Can someone settle an argument, please...
Since the XmlDocument class has neither a .Close() method nor does it
implement IDisposable, is there any point in even setting it to null...?
Setting a variable to null wouldn't call Dispose anyway. It's almost
always a mistake to set a variable to null after you've finished using
it.
E.g.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("<filespec>");
// retrieve an XmlNode object and change its InnerText property
xmlDoc.Save("<filespec>");
At this point, would the line below be of any benefit...?
xmlDoc = null;
Almost certainly not. The only situations in which it would be useful
are:
1) It's a member/static variable, and it's no longer useful even though
the rest of the instance might be. If it's a member variable, I'd have
another look at the design - usually I find that the whole of an object
is useful while any of it is.
2) It's used in a loop and after a certain number of iterations (before
the end) you know it won't be used any more. The JIT won't be able to
spot that you're not going to use it again, so it can't be garbage
collected until the loop finishes.
Both of these situations are rare - I can't remember the last time I
wrote a line like the above after the last use of a variable.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too