Link to home
Start Free TrialLog in
Avatar of blackbookcoder
blackbookcoder

asked on

objMSHTML As New MSHTML.HTMLDocument and leaking memory. How to terminate the object and stop the leaking memory?

Please look at this comment and then look at my code below
comment:   http://www.codeguru.com/vb/vb_internet/html/comments.php/c4815/?thread=54278
dispose of it in Form_Terminate?  How do I do that?

Code:
Module1.bas
Global AddrContent(10) As String  'an array already filled with web addresses

Form1
Option Explicit

Dim objMSHTML As New MSHTML.HTMLDocument
Dim objDocument As MSHTML.HTMLDocument
Dim BlankpgString2 As Long

Public Sub GetWebpage()
Set objDocument = objMSHTML.createDocumentFromUrl(AddrContent(GG3), vbNullString)

Do Until GG3 = 0

     While objDocument.readyState <> "complete"
   
          lblStatus.Caption = "Waiting for the document to load"
          DoEvents
          BlankpgString2 = Len(frmParser.txtSource.Text)
     Wend

    set objDocument = nothing
    set  objMSHTML = nothing
   'Even after setting the objects to nothing, it's still in memory
    GG3 = GG3 - 1
Loop
End Sub
Avatar of Erick37
Erick37
Flag of United States of America image

Shouldn't the line:

Set objDocument = objMSHTML.createDocumentFromUrl(AddrContent(GG3), vbNullString)

be INSIDE the Do Until GG3 = 0 Loop?

Do Until GG3 = 0
    Set objDocument = objMSHTML.createDocumentFromUrl(AddrContent(GG3), vbNullString)
    While objDocument.readyState <> "complete"
    '...


As it is now, you set the MSHTML docs to nothing and keep looping.  On the second pass, since you have not SET objDocument you should get an error.

Setting them to Nothing as you have is sufficient and there should be no memory leak.
Avatar of blackbookcoder
blackbookcoder

ASKER

yes my mistake the set document  should be inside the loop.  Even setting them to nothing still makes a memory leak when changing urls
How are you determining that there is a memory leak?
Erick37, I'm using AQtime version 4.20 found at:  http://www.automatedqa.com/downloads/
I can see three threads which are not being released.  You can also read about tracking down memory leaks with other tools like poolmon.exe as described in this article:  http://www.winnetmag.com/Articles/Index.cfm?ArticleID=4754
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial