View Single Post
 
Old 06-17-2014, 10:36 AM
whatsup whatsup is offline Windows 7 64bit Office 2010 32bit
Competent Performer
 
Join Date: May 2014
Posts: 137
whatsup will become famous soon enough
Default

Hm, no, that's not the right tool to make visible what's stored/remained in memory.

You have to distiguish between "validity" of a variable and it's "presence" in memory. These are different things: After passing e.g. "End Sub" the local variable isn't valid anymore and you can't access it - that's true -. But this doesn't mean necessarily that it isn't still alive within memory.
The watch window rather points out the validity than its presence in memory (though I'm not 100% sure about this).

To get a glimpse on memory you rather need something like ObjPtr() - which of course itself won't work after leaving the sub for local variables. For example have a look at this:
- Add a module and put the code.
- Add a userform which will be "Userform1"
- Then step through the code by F8 and watch the immediate window
Code:
Public Sub test()
    Dim objForm As Object
    Debug.Print ObjPtr(objForm)
    Set objForm = UserForm1
    Debug.Print ObjPtr(objForm)
    Set objForm = New UserForm1
    Debug.Print ObjPtr(objForm)
    Set objForm = Nothing
    Debug.Print ObjPtr(objForm)
End Sub
You will clearly see, that with "New UserForm1" a new entry is created in memory, though it's the same variable. Now, if you don't set it at the end to Nothing, memory keeps occupied, while setting it to nothing the entry in Memory = 0 which signifies it's removed from memory.

Now, I can't proof that this isn't the case if you don't destroy the reference manually but leave it to vba, because I haven't got any idea to read in memory what's in it.
Reply With Quote