Visual Basic Language Reference  

Nothing

The Nothing keyword represents the default value of any data type. Assigning Nothing to a variable sets it to the default value for its declared type. If that type contains variable members, they are all set to their default values. The following example illustrates this:

Public Structure MyStruct
   Public Name As String
   Public Number As Short
End Structure
Dim S As MyStruct, I As Integer, B As Boolean
S = Nothing   ' Sets S.Name to Nothing, S.Number to 0.
I = Nothing   ' Sets I to 0.
B = Nothing   ' Sets B to False.

If the variable is of a reference type — that is, an object variable — Nothing means the variable is not associated with any object. For example:

Dim MyObject As Object
MyObject = Nothing   ' No object currently referred to.

When you assign Nothing to an object variable, it no longer refers to any object instance. If the variable had previously referred to an instance, setting it to Nothing does not terminate the instance itself. The instance is terminated, and the memory and system resources associated with it are released, only after the garbage collector detects there are no active references remaining.

See Also

Object Lifetime: How Objects are Created and Destroyed | Dim Statement | Lifetime