Once you run a script, all the variables that are global are saved in memory until you restart your engine(AE here, but could be extendscript, illustrator etc). In order to not have this problem, you need to store your variables locally. To do that, the best practice in my opinion is use this kind of code as a frame for yours:
(function myScript(thisObj){
//here you write your code
})(this)
This function calls on itself, and all the variables you have are stored inside it. So when it stops running, you have no variable “leftover”.
As a fun fact. You can actually use a variable from a script into another script if it is stored globally.
I hope i answered your question.
Andrei
My Envato portfolio.