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?

Global AddrContent(10) As String  'an array already filled with web addresses

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"
          BlankpgString2 = Len(frmParser.txtSource.Text)

    set objDocument = nothing
    set  objMSHTML = nothing
   'Even after setting the objects to nothing, it's still in memory
    GG3 = GG3 - 1
End Sub
Who is Participating?
moduloConnect With a Mentor Commented:
PAQed with points refunded (500)

Community Support Moderator
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.
blackbookcoderAuthor Commented:
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?
blackbookcoderAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.