Leak with XmlTextWriter?

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
 
P

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top