memory leak in script??

R

Rea

Hey eb
can this be the reason for huge memory expansion ?
Doesn't this script free memory of the object it had created?

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
 
A

Anthony Jones

Rea said:
Hey eb
can this be the reason for huge memory expansion ?
Doesn't this script free memory of the object it had created?

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

I've just posted this answer in the components group. Please don't
multipost.



Setting an object variable to nothing does not free memory.

Assigning a new value (whatever it is not just nothing) to variable will
cause the release method of the any currently held reference to be called
before the reference is replaced by the new value.

Calling release on an interface reference (commonly known as an object
variable) causes the object to decrement an internally held count of the
number of references that have been made. When this count reaches zero then
it is the object's responsibility to deallocate any memory or other
resources it may be holding.

obj1 is passed byRef (the default mode in VBScript BTW) so the assigning of
Nothing to obj1 is applied to the variable of the same name in the
createCOMobject procedure. Since this is the only reference being held the
internal reference count of the object drops to zero and the object should
destroy itself at this point.

However without the line assigning nothing to the obj1 variable the obj1
variable is destroyed when the procedure createCOMobject returns, at this
point any reference currently held in obj1 has it's release method called.
Hence in this case the assignment of nothing is superflous.

HTH,

Anthony.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top