VBA memory allocation
I think you are right. I wrongly assumed that VBA was like JAVA and had a
'garbage collector' etc.
However, I dont know how to fix the problem. I'm getting an error when the
"collect.item(1)=nothing" line is called.
Here is the code:
Public Sub run()
Dim C As Collection
Set C = New Collection
Dim mc As Class1
Set mc = New Class1
C.Add mc
Set C.Item(1) = Nothing '<- Error thrown here
End Sub
The error is:
Run-time error '438':
Object doesn't support this property or method
Help.
" wrote:
You may be assigning the reference to your object to Nothing but not
actually removing the object from memory. What do you think of this?
i=1
iteration counter
While i<collect.count
set myobject = collect.item(i)
if myobject.isTimeToRemove then
set myobject = Nothing
set collect.item(i) = nothing
collect.remove(i)
else
sose to remove this item
i=i+1
endif
wend
Also consider changing the line
set myobject = Nothing
to a custom sub that sets the members of myobject to nothing.
|