Click to See Complete Forum and Search --> : [VBscript] why do you set variables to nothing?


aaron.martinas
02-14-2007, 09:07 AM
i understand that it "releases all the system and memory resources associated with the previously referenced object"... however, wouldnt it be a m00t point to release them at the end of a script when followed by a "wscript.quit" statement? or lets say there is no quit statement, but instead, the program executes all lines of code and finishes from "end of file" perspective.. wouldnt the objects be released when the process exited?

ultimately, im trying to determine if this is simply "good programming style" or if there is an actual functional reason for doing this.

russell
02-15-2007, 04:35 PM
both. we don't "know" when/if the garbage collector will clean up. we also want to free the memory acquired as quickly as possible, allowing other applications to use it.

it is also good style, and quite important in non-interpreted languages like C, where the memory is never released if we don't bother releasing it (until reboot).

as for resources like files and databases, not explicitly closing them not only hogs up valuable resources (beyond memory) you risk data corruption by failing to close the object.