Re: memory leak in script??
- From: mr_unreliable <kindlyReplyToNewsgroup@xxxxxxxxxxx>
- Date: Mon, 28 Aug 2006 10:17:48 -0400
hi Rea,
You have probably not gotten an answer to this as yet
for a good reason -- i.e., that is a difficult question.
For one thing, an object is not released until the
"reference count" (that is, the number of variables
holding a reference to the object) goes to zero --
regardless of whether you set it to nothing.
In the case you mention, "createOjbect" is holding
a reference (ojb1). You are passing this to
"useObject" where you set it to nothing.
Here's the rub. Setting it to nothing in the
second sub does not necessarily release the reference
count set up by the first sub. Perhaps somebody
more knowledgable will come along and clarify this.
Now for another problem. Even when the reference count
gets down to zero, that is NO GUARANTEE that the object
will be (instantly) released. The system only releases
objects "when it gets around to it". Here's the point
-- if you are running through you code in a tight loop,
creating thousands of objects in a very short time period,
the system may not have an opportunity to "get around to"
releasing your objects (and the corresponding memory
blocks associated with those objects).
It's too bad that vbs doesn't have a "DoEvents"
statement, but for the purpose of releasing the processor
so that the system can do housekeeping, "wscript.sleep"
will work just as well.
And for better insurance that the objects are truly
candidates for releasing, I would recommend instantiating
them and releasing them IN THE SAME SUB, to avoid any
confusion about the possibility of any lingering
unrecognized and unreleased references.
cheers, jw
____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
Rea wrote:
Hey eb.
can this be the reason for huge memory expansion while running the following (server side) script:
sub createCOMobject()
set obj1 = createObject("object1")
dim flag = 1
useObject flag,obj1
end sub
----------------------------------
sub useObject (flag, byRef obj1)
...
set obj1 = Nothing
end sub
Thanks for your attention
Rea
- Follow-Ups:
- Re: memory leak in script??
- From: Rea
- Re: memory leak in script??
- Prev by Date: Re: How to switch off warnings.
- Next by Date: Re: How to switch off warnings.
- Previous by thread: Re: Possible to generate visible objects in VBScript?
- Next by thread: Re: memory leak in script??
- Index(es):
Relevant Pages
|