Re: Can com+ Hotfix Rollup Package 27 fix my memory problem with WSH. CreateObject/CreateScript?
From: Gerry Hickman (gerry666uk_at_yahoo.co.uk)
Date: 11/24/04
- Next message: Gerry Hickman: "Re: WSH in VS.NET 2003?"
- Previous message: mostro: "Re: Create an Admin$ Share using the Create Win_32 class"
- In reply to: Al Dunbar [MS-MVP]: "Re: Can com+ Hotfix Rollup Package 27 fix my memory problem with WSH. CreateObject/CreateScript?"
- Next in thread: Al Dunbar [MS-MVP]: "Re: Can com+ Hotfix Rollup Package 27 fix my memory problem with WSH. CreateObject/CreateScript?"
- Reply: Al Dunbar [MS-MVP]: "Re: Can com+ Hotfix Rollup Package 27 fix my memory problem with WSH. CreateObject/CreateScript?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 24 Nov 2004 20:52:48 +0000
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:)
> 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.
> 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. 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?
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.
If people don't want to follow this advice that's fine, as long as they
don't start complaining!
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.
-- Gerry Hickman (London UK)
- Next message: Gerry Hickman: "Re: WSH in VS.NET 2003?"
- Previous message: mostro: "Re: Create an Admin$ Share using the Create Win_32 class"
- In reply to: Al Dunbar [MS-MVP]: "Re: Can com+ Hotfix Rollup Package 27 fix my memory problem with WSH. CreateObject/CreateScript?"
- Next in thread: Al Dunbar [MS-MVP]: "Re: Can com+ Hotfix Rollup Package 27 fix my memory problem with WSH. CreateObject/CreateScript?"
- Reply: Al Dunbar [MS-MVP]: "Re: Can com+ Hotfix Rollup Package 27 fix my memory problem with WSH. CreateObject/CreateScript?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|