At 11:02 AM 1/26/2005, Paul Mehner wrote (in part)
>Many developers are also under the mistaken impression that setting an
>object to Nothing will destroy it or somehow promote a faster clean up by
>the garbage collector -- or feel that it is necessary or somehow desirable
>because that the way it was done in VB6. Often former VB6 developers place
>extraneous "set object = nothing" statements near the end of every single
>routine as if they were laying non-effective sacrifices to the ancient VB6
>god. All this effort buys them nothing because it does not make the object's
>clean-up code to execute in a deterministic fashion and it seldom has any
>impact on the performance of garbage collection.

If you're talking about the local variable of a method, you are correct.  
However, if you are talking about class member that's an object reference, 
setting the reference to Nothing will allow the referenced object to be 
collected if your class instance was the only reference to it, even if your 
class instance is still alive (as far as the GC goes).

You might question the need for such an object to be a class member, but it 
could be that the object is only "in use" when the instance is in a particular 
state.  Setting the reference to Nothing when the object isn't needed any more 
is clearly useful in that case.

But to reiterate my agreement with your basic statement, adding (perhaps more 
than one) "localvar = nothing" to the bottom of a routine (as you were 
apparently encouraged to do in VB6) is a waste of time -- and I'm sure there's 
at least one routine out there that has a try/finally only so that the local 
object references can be set to Nothing in the Finally part.





J. Merrill / Analytical Software Corp

===================================
This list is hosted by DevelopMentor�  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to