1

Closed

Memory Leak for HtmlNode

description

HtmlNode.WriteTo() and HtmlNode.WriteContentTo() causes a memory leak not closing the StringStream opened.
 
public string WriteTo()
{
StringWriter sw = new StringWriter();
WriteTo(sw);
sw.Flush();
return sw.ToString();
}
 
Should be
public string WriteTo()
{
StringWriter sw = new StringWriter();
WriteTo(sw);
sw.Flush();
string s = sw.ToString();
sw.Close();
return s;
}
 
Or better yet, using {} block
Closed Oct 3, 2009 at 4:34 PM by DarthObiwan

comments

JerChap wrote Jan 11, 2009 at 8:52 PM

Does the StringWriter not handle it's own cleanup after it goes out of scope and the garbage cleanup hits it?

DarthObiwan wrote Oct 3, 2009 at 4:40 AM

Yep, the Using block would be the better way. Copying to the s string would just cause more memory to be used.
I'm incorporating a using block in the next release