Setting things to nothing ?

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?
 
M

Marina

No, you shouldn't. You are just adding more unecessary code that has to be
executed.
 
B

bruce barker

no gains other than increased cycle times. all stack variables are released
when a sub/function exits.

-- brice (sqlwork.com)
 
S

Sebastien Lambla

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top