Leak with XmlTextWriter?

  • Thread starter Thread starter Point.Cube
  • Start date Start date
P

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
 
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
 
Back
Top