Closed fiseekade closed 1 year ago
See #131.
In your analysis, can you dig down further and see which unmanaged resources are not released?
The managed IHtmlDocument
object returned by ParseDocument
is only held in a local variable inside the SanitizeDocument
method and is eligible for garbage collection when the method returns. Neither IHtmlDocument
nor the concrete implementation class HtmlDocument
implement IDisposable
so it shouldn't be necessary to dispose them.
Thanks for your response.
At this point, I'm not sure which are the unmanaged resources as this is buried in AngleSharp's library. I'd have to take a closer look to find out.
But in AngleSharp's library, HtmlDocument
inherits from Document
which has a Dispose
method - here is the link - https://github.com/AngleSharp/AngleSharp/blob/devel/src/AngleSharp/Dom/Internal/Document.cs
You're right. IHtmlDocument
does implement IDisposable
through IDocument
. I've added a using
statement.
Thanks for the quick response and fix. When would a new release be available?
I've just released 8.0.601.
I see that after running
SanitizeDocument(Stream html, string baseUrl = "", IMarkupFormatter? outputFormatter = null)
over many files for several hours, that the memory usage of my application keeps increasing and eventually runs out of memory. I've tracked down the memory leak to theSanitizeDocument
call which calls AngleSharpParseDocument
that returns aIHtmlDocument
that is not getting cleaned up it seems.To get around this memory leak issue, I had to switch to using the
SanitizeDom
function and then dispose of theIHtmlDocument
in my code. Can you fix theSanitizeDocument
function so that it disposes of theIHtmlDocument
? Thanks.