Re: How to terminate an object that's in a collection




Coll.Add MyClass, "Test"
Coll.Remove 1 'removes item from collection, but MyClass still exists
Set MyClass = Nothing 'Removes MyClass from memory

You are adding an object to the collection, but the object also exists in
memory outside of the collection. Any given object could possibly exist in
multiple collections. (Pretty sure that with custom classes you are adding a
copy of the object to a collection. In my experience, changing a property of
a 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 it
is the last outstanding reference to the object.

Coll.Add MyClass, "Test"
Set MyClass = Nothing 'removes 1st instance from memory (coll.count still
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.


.



Relevant Pages

  • Re: Object creation overhead
    ... one particular use is to reduce the memory ... 'MyClass'; this class looks like: ... 20,000 'String' objects is needed, both to manage them, and for the 'String' ... The 'proxy' class approach won't see a reduction in the number of 'MyClass' ...
    (comp.lang.java)
  • Re: C# confusion
    ... If you create instances of MyClass, ... you are allocating an area of memory for the data segment for each ... data members are initialised upon first reference of the class. ... static keyword; This one has been hitting me like a hammer on the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: del an imported Class at EOF... why?
    ... importing. ... it uses a lot of memory you could free up the memory for other ... from extern_module import MyClass ... I tend to always use the plain "import xmodule" form of statement, so just one symbol gets into my space. ...
    (comp.lang.python)
  • Re: C# confusion
    ... MyClass" then you will never create an instance of MyClass on the heap, ... so any instance members you declare in MyClass will never exist. ... of memory: not the stack and not the heap, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to terminate an object thats in a collection
    ... Dim C As Collection ... Dim tmp As Class1 ... My memory is pretty clear on this, but it is not clear on whether there ... Coll.Remove 1 'removes item from collection, but MyClass still exists ...
    (microsoft.public.excel.programming)