Thursday, September 16, 2004

The Debate: Should we set the value of a variable to Null after we have no use for it

Its been a long standing debate. I have found many developers setting the value of the local variables to null at the end of the method. That never made sense why should one set the value of a variable to null which will anyway be out of scope in the next line of code and will be garbage collected. It never made sense and it never will.
But Rico Mariani in his post Mid life crisis has pointed out a scenario where setting the value of the variable that are no longer used to null can be useful. But as he pointed out it in the post it needs to be done before we pass the task to some other thread and we know the variable is dead and will not be used in later processing. To understand in detail one must go through the article in detail and check out how the .Net Garbage Collector(GC) works.
learned something really interesting and useful today.

No comments:

Post a Comment