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

Posted on 2004-10-22
Last Modified: 2012-06-21
Please look at this comment and then look at my code below
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
Question by:blackbookcoder
    LVL 32

    Expert Comment

    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.

    Author Comment

    yes my mistake the set document  should be inside the loop.  Even setting them to nothing still makes a memory leak when changing urls
    LVL 32

    Expert Comment

    How are you determining that there is a memory leak?

    Author Comment

    Erick37, I'm using AQtime version 4.20 found at:
    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:

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

     Java Android Coding Bundle

    Whether you're an Apple user or Android addict, learning to code for the Android platform is an extremely valuable, in-demand skill. It all starts with Java, the language behind the apps and games that make Android the top platform it is today.

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    931 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now