However this is not necessary. When a given procedure finishes processing, the variables that were defined in that procedure go "out of scope" which means that their values are no longer available -- the task is complete and the variables are no longer needed. As the .NET Runtime executes, it looks ahead and decides when it needs to destroy an object, based on whether or not the object’s reference is used in future code. So, by waiting until the very end of the procedure to add this code:
myCar = null;
you might actually be hindering rather than helping the .NET
Runtime to clean up memory sooner. Although, lets be honest, it really won't make that big of a difference in smaller programs. However, in large memory-intensive applications or applications where there are a lot of simultaneous users such as a high-traffic web site, you might need to pay attention to this.
But this leads us to a best practice:
BEST PRACTICE: Don't attempt to help out the process of Garbage Collection by setting objects you are finished with equal to null.
Supplemental Readings for the Express Edition Videos Copyright © 2005 LearnVisualStudio.NET