Re: vbs output to txt file
- From: "Paul Baker [MVP, Windows - SDK]" <paulb@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 12 Apr 2007 09:36:05 -0400
"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
.
- References:
- vbs output to txt file
- From: Cactus Johnson
- Re: vbs output to txt file
- From: Richard Mueller [MVP]
- Re: vbs output to txt file
- From: TheScriptLibrary.com
- Re: vbs output to txt file
- From: Al Dunbar
- Re: vbs output to txt file
- From: mr_unreliable
- Re: vbs output to txt file
- From: Paul Baker [MVP, Windows - SDK]
- Re: vbs output to txt file
- From: TheScriptLibrary.com
- vbs output to txt file
- Prev by Date: Re: Need help with script
- Next by Date: Re: vbs output to txt file
- Previous by thread: Re: vbs output to txt file
- Next by thread: Re: vbs output to txt file
- Index(es):
Relevant Pages
|