C# automatically adds object references when you assign the object to another variable. C# 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:

referenceObj = otherReferenceObj;

You can initiate the release of a reference to an object by setting the variable to the value null, as shown in the following code:

referenceObj = null;