I haven't found an answer specific to this question so hopefully someone can clear it up for me.
I understand the VBA Garbage Collector uses a reference count to determine if an object is not longer required, and to explicitly disassociate a variable (thereby decrementing the reference count) you use:
Set objectVariable = Nothing
Here is what I have in a spreadsheet I'm working on right now:
Declare Function GetObject Lib "ObjectCreator.dll" () As Object
Public MyObject as Object
Sub MyMethod()
Set MyObject = GetObject()
...do stuff with MyObject...
Set MyObject = GetObject()
...do stuff with my new MyObject...
Set MyObject = GetObject()
...do stuff with my even newer MyObject...
Set MyObject = Nothing
End Sub
My question is: Do all three of the created objects get destroyed by the GC or only the last one? i.e. Does the reference count of an object get decremented when its referencing variable is set to another object rather than being set to Nothing
?