View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
vivmaha vivmaha is offline
external usenet poster
 
Posts: 42
Default VBA memory allocation

Ok guys.

I did something that I should have done hours ago: i made some simple
programs to test the memory mechanics in VBA.

It turns out that coll.remove(index) also frees memory of the object at
'index' PROVIDED THAT nothing else refers to the object. In fact coll=nothing
also does this. My memory isnt getting freed as something else is pointing to
the object i'm try to free. And i'll be spending the rest of this nice day
look for that.

Thanks for all ur help.
Vivek.

"vivmaha" wrote:

Hi,

I'm running a huge model on VBA, and I think i'm leaking memory.

In the following example, does the memory allocated for myInstance get freed
when I remove it from the collection? I assume that, like java, once the
memory is not referenced to, It gets deallocated.

dim myCollection as Collection
Set myCollection = new Collection
dim myInstance as MyClass
Set myInstance = new MyClass
myCollection.add myInstance
myCollection.remove 1

If the above does not free the memory, how do I do it?

Also, does VBA have constructors? And destructors?

Thanks.