Setting things to nothing ?

  • Thread starter Thread starter george d lake
  • Start date Start date
G

george d lake

Hi,
Quick question, should I set all my vars to Nothing when I exit a
Fucntion/Sub/Page?
Sample:

Public Sub MySub(ByVal Param1 as Integer)
Dim Var1 as String
Dim Var2 as TextBox
Dim Var3 as Integer
etc....

Try
Code.....
Catch oError as Exception
Code
Fianlly
Var1 = Nothing
Var2 = Nothing
Var3 = Nothing
End Try
End Sub


Should I do this for every function/Sub/Page?
 
no gains other than increased cycle times. all stack variables are released
when a sub/function exits.

-- brice (sqlwork.com)
 
I would say that setting to null have an effect on garbage collection if
you deallocate vars defined outside of the method scope. All the
variables you define in you rmethod scope will be marked when execution
quits the current scope.

All this to say, although in this example there's no need, for others it
is usefull.
 
Back
Top