Unloading An Array Of Objects

Quick question here. I have am working in Access 2000 using vba. I have an array of custom classes in my program. When I am done w/ the array can I just erase the objects or do I have to loop thru the array and set each object = nothing first?

Code Example: (How it works now)

Dim a As Integer
Dim Managers() As Object
a = 1
Do
a = a +1
ReDim Preserve Managers(a)
Set Managers(a) = New ReportingLevel
Loop Until a > 10
Erase Managers

JR2003 comment isn't entirely accurate. Objects in VB are only destroyed when every reference to the object has been deleted (i.e. explicitly set to Nothing). COM objects maintain an internal reference

JR2003 comment isn't entirely accurate. Objects in VB are only destroyed when every reference to the object has been deleted (i.e. explicitly set to Nothing). COM objects maintain an internal reference count (bascially telling it how many instances of an object are being used), this count is decremented each time a reference is released (i.e set to Nothing). When the reference count reaches 0 the object is destroyed.

You should always set all object variables to Nothing as a matter of good housekeeping and freeing resources when no longer needed.

carl_tawn's comment isn't entirely accurate either. You do not have to explicitly set an object to nothing to destroy it. Simply going out of scope (e.g. if the object was defined inside a function) or erasing an array that points to some objects (as in your code) will be sufficient to destroy the objects and free the memory used by them.

Suggested Solutions

Introduction
While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC. I didn't post completely correct code o…

As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…

Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…