Home All Groups Group Topic Archive Search About

Leak with XmlTextWriter?

Author
7 Feb 2006 4:42 PM
Point.Cube
Hi,
I ve a dll for generating xml files relation to a our internal schema.
when the application was tested in lab they found that there is a leak
in XmlTextWriter. All XmlTextWriter object created are never desposed
even I use flush() and close() methodes after each use.
here is an exemple:

public XmlNode ToXml()
{
                 System.Text.StringBuilder sb = new
System.Text.StringBuilder();
                 XmlTextWriter writer = new XmlTextWriter(new
System.IO.StringWriter(sb));
                 writer.WriteStartElement(mElementName);
                 writer.WriteAttributeString("oid", OID);
                 writer.WriteEndElement();
                 XmlDocument doc = new XmlDocument();
                 string result = sb.ToString();
                 if( result != "" )
                 {
                                   doc.LoadXml(sb.ToString());
                  }
                 return doc;
}

thaks for any idea,
Regards,
FF

Author
7 Feb 2006 4:47 PM
Point.Cube
the new code is:
public XmlNode ToXml()
{
                 System.Text.StringBuilder sb = new
System.Text.StringBuilder();
                 XmlTextWriter writer = new XmlTextWriter(new
System.IO.StringWriter(sb));
                 writer.WriteStartElement(mElementName);
                 writer.WriteAttributeString("oid", OID);
                 writer.WriteEndElement();
                 writer.flush();
                 writer.close();
                 XmlDocument doc = new XmlDocument();
                 string result = sb.ToString();
                 if( result != "" )
                 {
                                   doc.LoadXml(sb.ToString());
                  }
                 return doc;
}

Regards,
FF

AddThis Social Bookmark Button