X hits on this document

PDF document

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

179 views

0 shares

0 downloads

0 comments

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 views179
Page views179
Page last viewedWed Dec 07 19:48:48 UTC 2016
Pages73
Paragraphs821
Words15988

Comments