Dispose or not Dispose.. the writer created from XmlDocument thru navigator?
Do I really need to dispose the writer below?
DataContractSerializer _serialier...
var actual = new XmlDocument();
using (var writer = actual.CreateNavigator().AppendChild())
_serialier.WriteObject(writer, myObj);
If not then the code is simplified to:
DataContractSerializer _serialier...
var actual = new XmlDocument();
_serialier.WriteObject(actual.CreateNavigator().AppendChild开发者_运维知识库(), myObj);
If the object implements IDisposable, then you should call Dispose on it when you're done.
If you don't do that, then your code is dependent on the assumption that you don't need to do it. What happens when your code is later refactored such that the XmlWriter
being used is one that holds on to some resource?
精彩评论