The Nothing keyword is used to disassociate an object variable from an actual object.
Set Object = Nothing
? Object Is Nothing
Boolean = IsNothing(Object)
Use the Set statement to assign Nothing to an object variable. In many cases, this will clear the reference to the object and the object itself (for most Ocx objects for example and objects formed using CreateObject); the main exception to this are Forms (Ocx and all other types) and Windows which must be closed properly using the appropraite method or command.
Several object variables can refer to the same actual object. When Nothing is assigned to an object variable, that variable no longer refers to an actual object. When several object variables refer to the same object, memory and system resources associated with the object to which the variables refer are released only after all of them have been set to Nothing, either explicitly using Set, or implicitly after the last object variable set to Nothing goes out of scope.
All object variables are automatically cleared when they go out of scope. If you want the variable to retain its value across procedures, use a global variable, or create functions that return the object.
To check if an object has been set to Nothing, either the Object Is Nothing statement or IsNothing function can be used (they are interchangeable).
OpenW 1
Dim dis As New DisAsm // a new instance of disassembler object
// use the Disassembler
Set dis = Nothing // release object
Print (dis Is Nothing) // True
Print IsNothing(dis) // True
Do
Sleep
Until Win_1 Is Nothing // [Or] Until IsNothing(Win_1)
A reference to an OLE object can be stored in a an Object-type, which in fact is an IDispatch reference type, or a Variant.
Empty, Missing, Is, Null, Object, Set, Variant
{Created by Sjouke Hamstra; Last updated: 17/08/2020 by James Gaite}