# VBA : clean up unused variables or not



## hofje (Mar 3, 2009)

I try to tweak the VBA-function that I've written in VBA and I was wondering whether I should bother cleaning up any variables that I will not be using anymore. More details down below...
function (ACCESStableID as byte, _
other_variables as whatever_datatype_I_need _
)
call connectDB(ACCESStableID) 'now my code knows the table
QUESTION
call CALC(ACCESStable, other_variables)
end function

QUESTION: should I bother to free the memoryspace (set ACCESStableID = nothing) allocated to ACCESStableID or will this extra command just slow down my code instead of speeding it up (since it doesn't have to bother about remembering what ACCESStableID actually was)?

bytheway: this is about the simplest example (I'm not to worried about the amount of memory a byte, i.e. exactly one byte as it is an integer ranging from 0..255) will take; in real the cleaning up has to do with quite large arrays of doubles that once used are needless for the further code. Or is this just dependent on the amount of memory available (which should be plenty as the arrays are big but so is 4Gb - though about 2Gb are consumed by windows-processes).

ANY THOUGHTS?
thx Martin


----------



## Scott786 (Jul 10, 2008)

I think from a best practice POV you should definitely get rid of unused variables. It can also help maintenance so that people wouldn't think the variables are going to be used again. I personally wouldn't worry that much about speed of the program unless speed is required but I am sure there would be people who would think otherwise.


----------

