This link mentions a concept that is new to me - Destroying objects by letting a collection hold the reference to it, destroying the original instance and then when done, removing that member of the collection to destroy the object
I'm wondering if the same thing is true for collections of collections.
I created a public collection to hold values for forms to set and for queries to use. (I am putting a function that fetches the value in a query calculated field).
Anyway. The collection I created holds sub-collections containing values. Here is a simplified example.
Is it safe to assume that removing the member, as in - "Remove_it" - actually sets the sub-collection ("col" in this example) to Nothing?
I can find no other way to set it to Nothing.
I'm wondering if the same thing is true for collections of collections.
I created a public collection to hold values for forms to set and for queries to use. (I am putting a function that fetches the value in a query calculated field).
Anyway. The collection I created holds sub-collections containing values. Here is a simplified example.
Code:
Public colVals as New Collection --------------------------------------- sub test() Dim col as New Collection ' Add a value to a local collection col.Add "hi","hi" ' Add this collection to a global collection colVals.Add col, "col" Set col = Nothing ' The global collection now owns the reference to the collection End Sub ------------------------------------ Sub test_2() ' When you run this you can see the sub collection is still persistent MsgBox colGlobalVal.Item("col")("hi") End Sub ------------------------------------ Sub Remove_it() ' Presumably this destroys the sub collection just as ' Set col = Nothing ' would normally destroy it colGlobalVal.Remove ("col") End Sub
I can find no other way to set it to Nothing.
Comment