Memory problems when using HtmlAgilityPack?

I notice a memory problem when I leave the application for a long time. Actually, I am getting a memory exception. I try to understand what the problem is, and I was clueless until I let it run again, and I notice

I get a leak in this line every time html.LoadHtml(a_few_k_of_html);. I suspect the HtmlAgilityPack is leaking. I tried wrapping it when using and calling dispose, but that doesn't exist. This happens not only on this line every time, but I remember that I change several areas to use HtmlAgilityPack instead of parsing html with a regular expression

How can I deal with this memory problem without modifying the HtmlAgilityPack itself?

+5
source share
2 answers

I had the same problem. After processing the document, I set the instance of the document to null, and then GC.Collect (). The problem is resolved.

+2
source

Try using a method HtmlAgilityPack.HtmlDocument Load()using LoadHtml().

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(a_few_k_of_html));
doc.Load(ms);
ms.Close();// <-- Important
//Do whatever you want with HtmlDocument
+1
source

All Articles