Memory problems when using HtmlAgilityPack?

.net html-agility-pack memory-leaks

Question

I notice a memory problem when i leave my app running for a long time. I actually get a out of memory exception. I try to figured out what the problem was and i was clueless until i let it run again and i notice

I get the leak on this line everytime html.LoadHtml(a_few_k_of_html);. I suspect HtmlAgilityPack is leaking. I tried wrapping it in using and calling dispose but that doesnt exist. Not only does it happen on that line everytime but i remember changing a few areas to use HtmlAgilityPack instead of parsing html with regex

How do i deal with this memory issue short of modifying HtmlAgilityPack itself?

Popular Answer

I had same problem. After processing the document i set the instance of document to null and then GC.Collect(). Problem was solved.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why