Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does MyObj = Nothing release the objects memory/destroy it? 2

Status
Not open for further replies.

joelwenzel

Programmer
Jun 28, 2002
448
Hi,

I've created a bunch of objects with the CreateObject method. To destroy them do I just set them equal to nothing or is there a destroy function or something?
 
Setting equal to nothing will destroy the object and release the system resources for the object. The garbage collection has also gotten better in VBScript, so the system resources for an object are also released whenever the object goes out of scope. I still think it is good practice to explicitly release the resources however.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Does MyObj = Nothing
in fact:
Set MyObj = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
>Setting equal to nothing will destroy the object
>the system resources for an object are also released whenever the object goes out of scope

Not quite true. In both cases what actually happens is that the object's reference count is decremented by one. Only when the reference count equals zero is the object destroyed and resources released
 
You are correct as usual strongm. You could have several variable refering to the same object and the resources would only be released after they were all set to nothing or went out of scope. My mistake.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top