I'm not sure if this approach would work but you could try it:
Create within your loop a delete-statement for these unwanted created variable:
Let vDeletevariable = 'LET ' & YourVariableValue & '= null();';
Maybe this link is a kind of explanation: http://community.qlik.com/message/176351#176351
I see thats there's already an answer, but I have a simple remark to your script. You are using "SET varname2 = ;"
I clean all my variables by "LET varname2 = NULL();". With that it doesn't appear in the Variable Overview. So if you have the same varname you can simply use this. The solution of Marcus Sommer is more sophisticated or comes this from the Bug-Thread?
I can incorporate that into Marcus' answer - or edit it in that way.
That looks even better.
I cannot be sure, but I would guess that with your variation, the variables don't exist at all anymore and thus do not take any space whereas with my method, the variables still exist, albeit with no value assigned.
Can anybody confirm whether this is right?
Thanks a lot!
Thanks for the answer, Marcus.
In the end, I'm opting to use SET v = ;
1. It empties the variable so the value isn't stored (which is the point)
2. It retains the variable for the next run so it doesn't have to be created again
Neither of these are likely to be noticeable as variable allocation/deallocation is not system-intensive. It's more about best practices and deciding the best way to build something for future re-use.
As a side note, if I had a large, generic clean-up script that resets many (1000's) of the same variables across multiple scripts, I might opt for LET v = NULL(); instead. This is so the SET statements don't create needless variables that linger in applications where they are not used. But this is not a best-practice, either.