Possible memory leak in HTMLDocument?


#1
  1. Private Function ReadDatarowCollection(Code As String, Year As UShort, Quarter As Byte) As HTMLCollection
  2. Dim a As New HTMLDocument("http://vip.stock.finance.sina.com.cn/corp/go.php/vMS_FuQuanMarketHistory/stockid/" & Code & ".phtml?year=" & Year & "&jidu=" & Quarter)
  3. a.Dispose()
  4. Dim b As HTMLCollection = DirectCast(a.GetElementById("FundHoldSharesTable"), HTMLTableElement).Rows
  5. Return b
  6. End Function
I ran the function repeatedly with memory usage monitored. The memory usage rose with Dim a As New HTMLDocument, but didn't drop whena.Dispose(). The usage remained the same when the function was called again, and rose again for the New HTMLDocument, then still didn't drop when Dispose().

I think it’s very likely a memory leak. Dispose() doesn’t work. In application the function will be called thousands of times, so such leak is very serious, causing GBs of memory waste. What should I do?


#2

@Silver_Fang

Thank you for contacting support.

Would you please share a sample application reproducing it, including this method and function call with the values of parameters Code, Year and Quarter, so that we may try to reproduce and investigate it in our environment.


#3

With the following simple little demo, you should be able to reproduce it under win10 x64:

Imports Aspose.Html
Module Demo
Sub Main()
Dim a As Collections.HTMLCollection
While True
a = DirectCast(New HTMLDocument(“http://vip.stock.finance.sina.com.cn/corp/go.php/vMS_FuQuanMarketHistory/stockid/000722.phtml").GetElementById("FundHoldSharesTable”), HTMLTableElement).Rows
End While
End Sub
End Module

In my test, the memory usage gradually grew up to 1GB and showed no signs of limit. Moreover, the Dispose() method did no good:

Imports Aspose.Html
Module Demo
Sub Main()
Dim a As Collections.HTMLCollection, b As HTMLDocument
While True
b = New HTMLDocument(“http://vip.stock.finance.sina.com.cn/corp/go.php/vMS_FuQuanMarketHistory/stockid/000722.phtml”)
a = DirectCast(b.GetElementById(“FundHoldSharesTable”), HTMLTableElement).Rows
b.Dispose()
End While
End Sub
End Module

In this one each HTMLDocument is disposed after data extracted, but the disposition doesn’t suppress the memory growth at all.


#4

@Silver_Fang

Thank you for sharing requested data.

We have have been able to notice huge memory consumption, in our environment. A ticket with ID HTMLNET-1205 has been logged in our issue management system for further investigation. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.


#5

Any workaround? It’s excruciating to find a substitute functionally handier than Aspose.


#6

@Silver_Fang

The issue reported by you has just been logged in our issue management system. We will be able to share our findings once it is investigated in our environment. Please be patient and spare us little time.


#7

@Silver_Fang

Thank you for being patient.

We would like to share with you that the issue reported by you, HTMLNET-1205, has been resolved in Aspose.HTML for .NET 18.6.. However, instead of using:

b.Dispose()

Please use below code snippet, where b is the instance of HTMLDocument class.

b.Context.Dispose(); //this code frees maps with JS timers
b.Dispose();

We hope this will be helpful. Please feel free to contact us if you need any further assistance.


#8

The issues you have found earlier (filed as HTMLNET-1205) have been fixed in this update.