Re: Can com+ Hotfix Rollup Package 27 fix my memory problem with WSH. CreateObject/CreateScript?

From: Al Dunbar [MS-MVP] (alan-no-drub-spam_at_hotmail.com)
Date: 11/26/04


Date: Thu, 25 Nov 2004 18:32:24 -0700


"Gerry Hickman" <gerry666uk@yahoo.co.uk> wrote in message
news:OubZQem0EHA.3292@TK2MSFTNGP10.phx.gbl...
> Al Dunbar [MS-MVP] wrote:
>
> > Ouch! my face is still stinging from this slap, however well deserved it
> > might be!
>
> Heh, well it wasn't aimed at you:)

Heh, improve your aim, then... ;-)

> > I agree with *most* of what you say above (mainly the importance of
> > <explicitly> closing files, recordsets, and connections), mainly because
> > these activities have effects that are felt outside of the scope of a
script
> > by an object that has its own existence in that external domain.
>
> Yes.
>
> > Contrariwise, it seems to me that the de-instantiation of objects is
done
> > automatically by WSH. I just did a test using a class created for the
> > purpose, which indicates that its terminate event is invoked by any of
the
> > following:
>
> We don't have this hand-holding "terminate" event in JScript so it's the
> first time I've seen it, but I don't think it changes much. You can put
> your clean-up code in the "terminate" event if you like, but at the end
> of the day, it's no different to calling Dispose() manually. You'd have
> to do it that way in COM anyway. Of course in script, the object will be
> destroyed sooner or later, but with a long script with looping you
> ignore best practice at your own risk.

The difference is, if it is someone else's class (or COM object) we are
using and they have done it "right", we will not have to explicitly Dispose,
or explicitly do anything.

> > to the same object, memory and system resources associated with the
object
> > to which the variables refer are released only after all of them have
been
> > set to Nothing, either explicitly using Set, or implicitly after the
last
> > object variable set to Nothing goes out of scope."
> > Even the above definition makes no distinction between object variables
> > being set to nothing and going out of scope, other than to call one
explicit
> > and the other implicit.
>
> I know and I agree. I think you've looked into it in much greater depth
> than I have, and I'm in no doubt your code releases everything
> perfectly.

Very flattering, but I make no claims of perfection...

> However:
>
> What I'm saying is much more basic than that. I haven't gone into
> details and probably don't need to, what I'm saying is that no one needs
> to worry about this, because if they follow best practice as outlined in
> my earlier message, they'll never run into this problem in the first
> place. Why take a risk if you don't need to? People are going to have to
> program this way as soon as they look outside VBScript, so why not start
> now?

Now we're talking the same language (as if you thought we ever would! ;-). I
agree that following best practice is almost always worth the extra effort -
in fact, in the long run it reduces the effort. But this applies to a number
of aspects of coding practice in addition to releasing all objects when they
are no longer required. It would be silly, in my view, to insist religiously
on that one aspect while ignoring the others. I think the best approach is a
balance among them all.

> As an example of not calling Dispose(), I have a class called Reg() that
> is all about managing remote registries. Reading and Writing dozens of
> values to hundreds of machines is a walk in the park, but what it can't
> do (for performance reasons) is close the connection until I call the
> destructor. If I don't call it, I'll have a gazillion network sessions
> open on my network - not good. Obviously I don't want to open and close
> a connection every time I read or write a key, so it's catch-22. That's
> why I open the connection once, do the work, and the close it once. In
> COM there's even a reference counter for this. Scripters should
> implement their own reference counter and pretend they're programming in
> COM.

Certainly a good suggestion in the context of the type of script you are
talking about here.

> If people don't want to follow this advice that's fine, as long as they
> don't start complaining!

If they don't follow the advice, what have they to complain about?

> WSH is not as fool-proof as some people think. For example if you exec
> "SLEECT * FROM CIM_DataFile" on a modern computer with a few mapped
> drives, you could find yourself with a processor intensive process
> running solid for over two hours - hit CTRL+C in cscript and your script
> will stop (kind of), but it won't stop that process eating all your
> resources for the next two hours.

Is that an indication of a weakness on WSH's part, or of the WMI
infrastructure (or whatever) that is providing the query functionality?

/Al



Relevant Pages

  • Re: Sound of j and z in Hindi films and songs
    ... "Official Policy" to remove the dots from j-dot etc, ... there was a practice of writing an anuswar on certain words like ... the dictionaries and the script followed later. ... I also notice that the more vibrant a language more tolerant it is. ...
    (rec.music.indian.misc)
  • Re: why add script-tag in header section ?
    ... Validity with regard to attributes has never been shown to have a significant negative impact on scripting, but fully valid HTML has the advantage of being easily verified. ... There are far fewer restrictions on the placement of SCRIPT elements in HTML documents, and there is no reason for imposing additional arbitrary restrictions on their placement. ... Whenever anyone proposes a best practice, it is a good idea to require that they state a justification for that practice, in such a form that it is understandable, reasoned and convincing. ...
    (comp.lang.javascript)
  • Re: [opensuse] Need some help with a script
    ... The alternative is having to specify the full explicit path to every binary, and shell built-in, you ever run, not just by hand but in every script and even compiled into many binaries. ... explicitly want to run some transient local temp file. ... If it's not a transient temp file and will be used more than once, then you can move it into ~/bin which can be in PATH and have your convenience just fine. ...
    (SuSE)
  • Re: Javascript Best Practices Document v1.0
    ... that document.formsis a bad practice when it is a DOM 2 HTML valid practice in XHTML ... client-side form validation), then use an id attribute, or pass references directly and omit an identifier entirely. ... There is no general rule for returning false in a script, ...
    (comp.lang.javascript)
  • Re: Active Directory password expiry notification via email??
    ... I don't think that there is a way to do this natively but you could write a script that compares todays date with the Users PasswordExpirationDate property. ... New York, New York 10024-5192 ... Hacking, like any art, will take years of dedicated study and practice to master. ... SensePost willl be at Black Hat Vegas in July. ...
    (Security-Basics)

Quantcast