This project has moved. For the latest updates, please go here.
2
Vote

Not disposing unmanaged objects

description

Hi,

I really like the work you've done.

However, we are getting strange exceptions in our Outlook 2010 Add-In I'm using the library in.

I noticed that don't dispose of unmanaged objects nor use a using() block.

Do you plan to add this to your code?

For example this code found in many places "StreamReader sr = reader as StreamReader" is never disposed of.

Karl

comments

Venom0218 wrote Mar 10 at 10:57 PM

Hello,

Im ok with you.

It would be necessary to be able to
using (HtlmDocument doc = new HtlmDocument() )
{
   //some code here
}
It does not collect enough often for the amount of allocation I make with HtmlAgilityPack.

I have make some test comparaison with Visual Studio and another project who parse the Dom to.

Here the test code:
  Stopwatch chrono = new Stopwatch();
            long HtmlAgilityPackTimer, AngleSHarpTimer;

            chrono.Start();
            for (int i = 0; i < 100; i++)
            {
                HtmlAgilityPack.HtmlDocument Hdocument = new HtmlAgilityPack.HtmlDocument();
                Hdocument.LoadHtml(contentToTest);
            }
            chrono.Stop();
            HtmlAgilityPackTimer = chrono.ElapsedMilliseconds;
            chrono.Reset();

            chrono.Start();
            for (int i = 0; i < 100; i++)
            {
                AngleSharp.Parser.Html.HtmlParser parser = new AngleSharp.Parser.Html.HtmlParser();
                var document = parser.Parse(contentToTest);
            }
            chrono.Stop();
            AngleSHarpTimer = chrono.ElapsedMilliseconds;

            MessageBox.Show("HtmlAgilityPack: " + HtmlAgilityPackTimer + "ms" + Environment.NewLine +
               "AngleSharp: " + AngleSHarpTimer + "ms");
The "contentToTest" var is a dump of a simple DOM.

Here the results:
Image

You are the most fastest and it's because i prefere to use your project.

Here the results of memory allocation:
Image
In yellow the number of byte allocated.

HtmlAgilityPack use a lot of memory.

Please make the HtmlDocument Disposable for make the world great again.

Thank you !

Ps: Sorry for my english