Re: vbs output to txt file



"It is probably not necessary with some objects" - It's not necessary with
any objects.

"don't know all the low level processing that goes on in the innner workings
of Wsh" - All you need to know is that when you set a variable to nothing,
if it is an object, the reference count to that object will be decremented.
And if it goes out of scope, guess what happens, the reference count to that
object will be decremented. If the reference count reaches 0, the
implementor is expected to destroy the object. If not, they must not.

Note that someone commented on the Microsoft blog article that they set an
object to nothing to ensure that the object is destroyed (or some similar
wording), in case the reference counting of the object does not work. First,
why are you using a third party library you can't trust to reference count
properly? Second, it does not ensure that the object is destroyed. All it
does is decrement the reference count. As does going out of scope :)

If there are interdependant components that are poorly written, they may
expect you to release them in a particular order, but you didn't mention
anything about that. You are religiously setting objects to nothing and not
claiming to pay any attention to the order.

The Microsoft blog article also mentioned that you might want to set a
variable to nothing in the middle of a procedure because you don't need it
any more and you know it's not going to go out of scope yet. Again, anyone
who is religiouslly setting objects to nothing is not paying attention to
this. They're probably just setting it to nothing at the end, not the
middle, when it's about to go out of scope anyway.

Do you have any examples of your 1% of the time where you believe it is
necessary? Perhaps we can have a more productive discussion if we limit it
to tangible cases.

Paul

"TheScriptLibrary.com" <marty.lindsay@xxxxxxxxx> wrote in message
news:1176346522.608435.10470@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Apr 12, 5:26 am, "Paul Baker [MVP, Windows - SDK]"
<p...@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
Most of the people I work with do not express an opinion about "set obj =
nothing" (even when the variable "obj" is about to go out of scope).
Every
one of those that does insists that I must do it. I argue with them every
time and I refuse to do what they say. Not because I read anything that
tells me one way or another. Just because to me it's obvious that their
arguments are bogus.

These objects are COM objects and reference counted through the IUnknown.
Going out of scope is a decrement of the reference count. Just because it
is
not obvious that VB or VBScript is doing all this magic for you doesn't
mean
that it is not.

Paul

"mr_unreliable" <kindlyReplyToNewsgr...@xxxxxxxxxxx> wrote in message

news:uUYEnyFfHHA.3632@xxxxxxxxxxxxxxxxxxxxxxx



Al Dunbar wrote:
There is a school of thought that says this is not actually required
to
do this religiously in all cases. As I understand it, when a function
or
sub returns, or a script ends, the script engine effectively releases
all
object variables going out of scope.

Here is a link to Eric Lippert's (ms employee and scripting
engine developer) famous blog, saying that setting objects
to nothing is a waste of time (and also making very dis-respectful
comments about anybody who does):

http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx

As for myself, I religiously set objects to nothing when finished
with them, and so am seriously lacking in both scripting expertise
and mental capacity, at least according to Eric.

This peculiarity is partially due to initially copying code out
of the scripting documentation, where set object = nothing is
routinely used. It was subsequently reinforced by moving over
to the system api world, where failing to release any system
objects resulted in "memory leaks", and if allowed to persist
"memory leaks" can bring down hour system. So a habit of
explicitly releasing objects was developed. And finally, there
is just a slight bit of counter-culture sympathy at work here.
That is, if a microsoft expert says DON'T DO IT (set obj = nothing),
then I take some perverse satisfaction going against the
prevailing wisdom. I guess that ends any possibility of ever
having a career with microsoft...

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)

I thought that my comment would produce a few replies ;)

The reason I set objects to nothing is mainly due to a habit of being
as consistent and thorough as possible when scripting, and indeed with
anything to do with computers. I tend to agree that this is probably
not necessary with some objects, but my theory is that if I treat them
all the same, then the 1% of things that need setting to nothing wont
catch me out by surprise one day. Also, being consistently thorough
allows the copying of snippets between scripts without too many
unexpected problems..
At the end of the day I don't know all the low level processing that
goes on in the innner workings of Wsh, but if there are problems
caused by bad habits, I know the exact scope of the problem and don't
have to go guessing about which of my scripts it affects.

..Happy Scripting

Marty Lindsay
TheScriptLibrary.com



.



Relevant Pages

  • Re: beginner Qs about COM/.NET (context = exposing a pre-existing app to scripting)
    ... > therefore contain mutexes to access the serial port. ... Scripting languages, at the moment, only can deal with COM objects. ... > sense to me how reference counting fits into the picture. ... you don't need a mutex at all. ...
    (microsoft.public.vc.atl)
  • Re: Lock-free reference counting
    ... The scope of t is the entire function foo, ... The reference's lifetime is considerably shorter than ... The only way for it to collect it is if no reference is ... Bindings are introduced by various language constructs. ...
    (comp.programming)
  • Re: Lock-free reference counting
    ... scope and value lifetimes are completely separate concepts. ... reference is dropped, then the object could be immediately destroyed ... the mere act of destroying ... so scope-based reference counting keeps values alive a lot longer ...
    (comp.programming)
  • Re: Article of interest: Python pros/cons for the enterprise
    ... create a less flexible Python feature that achieves the ... you can create a temporary object whose reference count will become ... especially in a complex multi-statement scope. ... If you can then request that arbitrary actions be taken automatically when those events happen, you can pair up resource acquisitions and releases very easily. ...
    (comp.lang.python)
  • Re: vbs output to txt file
    ... nothing" (even when the variable "obj" is about to go out of scope). ... Going out of scope is a decrement of the reference count. ... Here is a link to Eric Lippert's (ms employee and scripting ... I religiously set objects to nothing when finished ...
    (microsoft.public.scripting.wsh)