Hello,
When writing utilities to process various information, I have often been remiss in considering 'Set object = Nothing', and notice that many others also forget; where object can be something like oLevel or oModel, oElement, etc.
How important is this requirement, or is there a way to process what memory to free up when a file is being closed; does unload do this....?
Cheers, Colin
Objects in VB/VBA are, under the hood, smart pointers that are reference counted.
A VBA object is allocated dynamically, with its memory address stored in the smart pointer. Each time your code assigns a variable to an object, the smart pointer increments an internal counter. Each time your code explicitly stops using an object, the internal counter is decremented. When the internal counter reaches zero, the memory is deallocated.
In complex situations, for example when an object is stored in an array or some other collection (e.g. ElementEnumerator or Dictionary), the allocated memory lifetime is hard to discern. Using Set o = Nothing makes it absolutely clear, both to the programmer and to VBA, that you don't intend to use that object any longer.
Regards, Jon Summers LA Solutions
Answer Verified By: cweber