Deleting Objects

After you have created an instance of a Component Object Model (COM) object, you can delete the object when it is no longer being used. Deleting the object frees system resources.

Each object has a counter that tracks the number of variables that refer to it. Only when this counter equals 0 can the object be deleted. So, to delete an object you must destroy all variables that refer to that object. For example, in the code below, ob1 is a variable that refers to ob:

ob1 = ob

ob = Nothing     ! object not destroyed

ob1 = Nothing    ! object destroyed

Note that all objects are automatically deleted when the application ends or when the program is aborted.