Indeed, for local variables, even setting them to Nothing on the next line after their last usage is counter-productive. Consider this :
Sub f() Dim o as New MyClass o.DoSomething() ' ... more code not referencing 'o' End Sub In release builds, the 'o' local variable stops preventing the GC from collecting the object as soon as the DoSomething() method is entered. In effect, the compiler sets it to Nothing for you even sooner than you could explicitly express it. By the time Close() returns, the object may well have been collected already. See here for a nice example of this behaviour : http://blogs.gotdotnet.com/anathan/PermaLink.aspx/8ec0b7b2-6290-4500-a8c7-1b6c677214cb Cheers, --Jonathan ----- Original Message ----- From: "Chris Anderson" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, September 29, 2003 10:24 AM Subject: [lists] Re: [ADVANCED-DOTNET] The timeout period elapsed prior to obtaini ng a connection from t he pool. > - setting null/nothing is not needed for locally defined > objects, these > objects are "marked" for collection as soon as they go of > scope, since they > are not reachable anymore. FWIW setting to null/nothing can actually have detrimental effects on the GC. If you set to null/nothing at the end of a routine, and the last time it was used was near the beginning, then if a GC occurred some place in the middle, the setting to null/nothing would actually be classified as a use, and the object would not be eligible for collection. So if you do set to null/nothing, make sure you do it immediately you are finished with it. =================================== This list is hosted by DevelopMentor� http://www.develop.com NEW! ASP.NET courses you may be interested in: 2 Days of ASP.NET, 29 Sept 2003, in Redmond http://www.develop.com/courses/2daspdotnet Guerrilla ASP.NET, 13 Oct 2003, in Boston http://www.develop.com/courses/gaspdotnet View archives and manage your subscription(s) at http://discuss.develop.com
