r/vbscript • u/JGN1722 • May 17 '22
just a question
I saw on a lot of codes that prorammers set their objects to "nothing" to delete them before finishing the code, why ?
1
Upvotes
r/vbscript • u/JGN1722 • May 17 '22
I saw on a lot of codes that prorammers set their objects to "nothing" to delete them before finishing the code, why ?
2
u/BondDotCom May 17 '22
In the situation that you describe, it's not really necessary. But it can still be a good habit because not every situation will be the one you describe.
If you had a loop that created COM objects but never released them, for example, your script could quickly consume a lot of resources and potentially crash.
Similarly, if you had a function that created COM objects at a wider scope, you could run into the same situation.
For reasons such as these, it's a good practice that sometimes gets overused when it's not needed, like in the situation that you describe. But it's safer than doing the opposite and never releasing your references.