X hits on this document

PDF document

“Beginning Visual C# 2005 Express Edition Video Series” - page 32 / 73





32 / 73

However this is not necessary. Older versions of Visual Basic required you to do this, but you don’t have to anymore. 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 (as is a common practice in previous versions of Visual Basic):

myCar = Nothing

  • 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 nothing.

Supplemental Readings for the Express Edition Videos Copyright © 2005 LearnVisualStudio.NET


Document info
Document views247
Page views247
Page last viewedSat Jan 21 05:14:27 UTC 2017