Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50236

Coding Convention Questions #2 (To clean up or not to clean up)

$
0
0
Here's the 2nd question. I have come across conflicting ideas on cleaning up variables before exiting a procedure.

Suppose we have a sub like so:

Code:

Sub MySub()
Dim lngLong as Long
Dim varVariant as Variant
Dim strString as string

'do something here

ExitProcedure:
'do we clean? if so, what?
End Sub

Now the 3 schools of thought I am comparing:
  1. Forget about cleaning up. VBA automatically scraps all procedure level variables when the sub ends, you don't need to waste effort and code bloat your procedure by carefully setting all procedure variables to vbNull/vbNullString/Nothing
  2. You MUST clean up all procedure variables before ending the sub (Then hint darkly at possibly dangerous vague consequences apparently caused by VBA not always cleaning up after itself?)
  3. If you have objects in your sub then you really should erase the objects. All other procedure level variables can be ignored (they don't need to be erased/reset).

So. I'm confused. Can anyone throw some light on this?

Viewing all articles
Browse latest Browse all 50236

Trending Articles