mayayana
Tue Jan 30 09:42:28 CST 2007
I imagine you may be confused by now. :)
But the three answers here are all saying basically
the same thing. It's more confusing because
it's so easy. When you use CreateObject, the
script host has to load the actual file for that
into memory. When you set the object to nothing
(or the object variable, as Al points out) you're
telling the host you're through with the object.
The "ref-counting" is the process that happens
behind the scenes, whereby the number of references
to an object are tracked, so that when the last
reference is released the file can be unloaded
from memory.
None of that is very clear because VBScript tries
to hide all the work and make it easy. In VBS you
can usually get away with ignoring the whole issue,
and many people do because they haven't been
encouraged to understand it. So the idea of setting
things to Nothing ends up seeming like a vague,
theoretical idea that doesn't really affect code. One
of the official Microsoft script experts even wrote
a well known article wherein he adamantly insists
that using "Set x to Nothing" is a problem!
http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx
His position is a bit irresponsible, because it relies
on the WSH to be absolutely foolproof and discourages
script users from understanding the inner workings, but
it's in line with the attempt to make script easy and
accessible to people without them needing to understand
how it works.
> Instead of set x=nothing does it do the same
> thing to do this:
>
> x=""
>
>
> After all when you set x=nothing you find
> that x is still an object.
>
> set x=nothing
> msgbox isObject(x) 'still object
>
> Thanks,K
>