Re: memory leak in script??

Tech-Archive recommends: Fix windows errors by optimizing your registry



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
.



Relevant Pages

  • Re: memory leak in script??
    ... I tried referencing there windows script host (wscript) ... "reference count" (that is, the number of variables ... count set up by the first sub. ... but for the purpose of releasing the processor ...
    (microsoft.public.scripting.vbscript)
  • Re: Why form load being called by Uload Me call?
    ... Does it reference your main form? ... I notice you are not doing an "Unload ... the only reason I put it modal was so Sub Main could set it to nothing ... for no reason other than to close an object in the same scope where it was ...
    (microsoft.public.vb.general.discussion)
  • RXParse module v.91 (by robic0)
    ... # Unicode character reference ... sub original_content ... then call content handler with $content ...
    (comp.lang.perl.misc)
  • Re: Emailing a Report
    ... make sure you have a reference to a Microsoft DAO Library ... The Sub LoopAgmtsSendEmail is highlighted by the Debugger. ... 'pSQL -- defines the recordset to open ... You must remember to enclose literal values in quotes and concatenate them; the final string must have commas too, ...
    (microsoft.public.access.modulesdaovba)
  • Re: Please help me clarify these byVal vs. byRef subtleties
    ... ByVal & ByRef Parameters are independent of Reference & Value Types. ... > I've got a class, DataHider, with one private string field (i.e., ... > Public Sub callObjectMethodPassedByVal(ByVal myObj As ...
    (microsoft.public.dotnet.languages.vb)