Free up memory: how to delete variables when I put them on - VBA VB ACCESS

How to free memory?

Say I have a line

Dim TestStri As String TestStri = "Test" ' What do i have to type up to get rid of the variable? ' I know TestStri = Nothing ' will give it the default value, but the variable is still there. 

Is it possible to use the same method for other variables, i.e. Long, int, etc.

+6
source share
1 answer

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.

+6
source

Source: https://habr.com/ru/post/926364/


All Articles