Free up Memory: How to delete variables once am don with them- VBA VB ACCESS

I'm assuming you are referring to VB6 and VBA as indicated by your title, not VB.Net, as indicated by a keyword.

In VB6 and VBA the memory consumption of a string variable consists of a fixed part for the string's length and a terminator and a variable length part for the string contents itself. See http://www.aivosto.com/vbtips/stringopt2.html#memorylayout for a good explanation of this.

So, when you set the string variable to an empty string or vbNullString, you will be freeing up the variable part of the string but not the fixed part.

Other types like long, int, bool and date consume a fixed amount of memory.

You can't "free" local variables in VB completely (come to think of it, is there ANY programming language where you can do that?), and for the most part, you wouldn't care because the local variables themselves (the fixed portion) is usually very small.
The only case I can think of where the memory consumption of local varibles could get big is if you have recursive function calls with deep recursion/wide recursion.

Tags:

Vba