I assume that you are referring to VB6 and VBA as indicated in your title, and not to VB.Net as indicated by the keyword.
In VB6 and VBA, the memory consumption of a string variable consists of a fixed part for the length of the string and the terminator and a part of the variable length for the contents of the string. See http://www.aivosto.com/vbtips/stringopt2.html#memorylayout for a good explanation of this.
So, when you set a string variable to an empty string or vbNullString, you release the variable part of the string, but not the fixed part.
Other types, such as long, int, bool, and date, consume a fixed amount of memory.
You cannot completely βfreeβ local variables in VB (think about it, is there any programming language where you can do this?), And for the most part you don't care, because local variables themselves (the fixed part) are usually very small.
The only time I can think about where the memory consumption of local variables can increase is if you have recursive function calls with deep recursion / wide recursion.
source share