Re: How to terminate an object that's in a collection
- From: "Peter T" <peter_t@discussions>
- Date: Tue, 26 Jun 2007 19:04:56 +0100
Thanks for provided a work around though.
It wasn't a workaround, it was the correct way to remove an item from a
collection, and with no other pointers to the class will destroy the class
(some rare exceptions with 'circular object references')
Probably best not to think of a collection item as an object variable.
Another way to refer to multiple instances of the same class would be with
an array, eg
Dim arrClass() as Class1
Redim arrClass(0 to 3)
Set arrClass(0) = New Class1
' code
arrClass(0).myMethod blah ' intellisence here
set arrClass(0) = nothing
Regards,
Peter T
"vivmaha" <vivmaha@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4A27A694-9B91-4A5A-B636-0EFEEB6AF54D@xxxxxxxxxxxxxxxx
Hi,exists
My problem is that I dont have references to things in the collection.
I can iterate through the collection, instance the items, and do exactly
what u did, but i wanted to know why the "Set collec.item(1) = nothing"
throws an error.
Thanks for provided a work around though.
"George Nicholson" wrote:
Coll.Add MyClass, "Test"
Coll.Remove 1 'removes item from collection, but MyClass still
inSet MyClass = Nothing 'Removes MyClass from memory
You are adding an object to the collection, but the object also exists
inmemory outside of the collection. Any given object could possibly exist
adding amultiple collections. (Pretty sure that with custom classes you are
property ofcopy of the object to a collection. In my experience, changing a
ita custom object in one collection will not "update" the same object's
property in another collection.)
Removing an object from a collection won't remove it from memory, unless
stillis the last outstanding reference to the object.
Coll.Add MyClass, "Test"
Set MyClass = Nothing 'removes 1st instance from memory (coll.count
equals 1)
Coll.Remove 1 'removes object from collection and memory
HTH,
"vivmaha" <vivmaha@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F9730525-3BFF-4A23-A12E-E117F3B425CB@xxxxxxxxxxxxxxxx
"Coll" is a standard VBA Collection object.
The first item in it is a MyClass object.
How do I delete this object? (and free the memory used)
This does not work:
Coll.remove 1 'The memory of item 1 is still allocated
This crashes:
Set Coll.item(1) = nothing '<Crash occurs here (Err 438)
Coll.remove 1
Thanks.
.
- References:
- Re: How to terminate an object that's in a collection
- From: George Nicholson
- Re: How to terminate an object that's in a collection
- Prev by Date: Re: Reset conditional color VB
- Next by Date: Re: inverse fourier
- Previous by thread: Re: How to terminate an object that's in a collection
- Next by thread: Re: COMPARE TODAY WITH DATE IN COLUMN
- Index(es):
Relevant Pages
|