Adding and Releasing References in Microsoft Visual Basic .NET
- Updated2026-07-27
- 1 minute(s) read
Microsoft Visual Basic .NET automatically adds object references when you assign the object to another variable. Visual Basic .NET also automatically releases object references when a variable or list that contains a reference to an object goes out of scope. Local variable scope ends when the function returns.
The following code is an example of assigning an object to a variable:
Set ReferenceObj = OtherReferenceObj
You can initiate the release of a reference to an object by setting the variable to the value Nothing, as shown in the following code:
Set ReferenceObj = Nothing