Solved

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

Posted on 2004-10-22
1,228 Views
Last Modified: 2012-06-21
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
0
Question by:blackbookcoder
    5 Comments
     
    LVL 32

    Expert Comment

    by:Erick37
    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.
    0
     

    Author Comment

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

    Expert Comment

    by:Erick37
    How are you determining that there is a memory leak?
    0
     

    Author Comment

    by:blackbookcoder
    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
    0
     

    Accepted Solution

    by:
    PAQed with points refunded (500)

    modulo
    Community Support Moderator
    0

    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 (http://www.experts-exchange.com/Q_27402310.html) 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