Clean up your toys when your done: Fighting memory leaks in your scripts
Posted by: Jerry Lees
One on the things you always want to do when you create objects in your scripts, especially objects from third party companies is, is to always remember to destroy the objects when you are done with them. At the very least, before you exit the script.
Object creation and not destroy the objects can be one source of memory leaks. In order to destroy an object should use the object’s .dispose method. If it does not have a dispose method, you set simply it to a special value of nothing. This will destroy the object and free up it’s memory. An example of using nothing is shown below:
Dim ObjTest
Set ObjTest = GetObject(”winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2″)
ObjTest = nothing



You must be logged-in to post a comment. Log-in/Register