Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Posted on 2004-10-22
Medium Priority
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?

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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 32

Expert Comment

ID: 12382462
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

ID: 12392097
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

ID: 12393207
How are you determining that there is a memory leak?

Author Comment

ID: 12396573
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

Accepted Solution

modulo earned 0 total points
ID: 12624134
PAQed with points refunded (500)

Community Support Moderator

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

609 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