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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

destroying objects 1

Status
Not open for further replies.

nigz

Programmer
Jun 15, 2001
60
GB
In vb 6 you set an object to nothing. What's the best way to destroy an object and force garbage collection?

I have used the following code to destroy a form, it works but seems a bit 'over the top' - grateful for your suggestions.

frmNew.Close()
frmNew.Dispose()
frmNew = Nothing
 
Don't bother.....

Let the Garbage Collector do it for you.....

Craig
 
Do bother to Close forms and set any reference that will not go "out of scope" to Nothing. Then let GC do its work in time.
frmNew.Close()
frmNew = Nothing
Dispose is described as
"This member supports the .NET Framework infrastructure and is not intended to be used directly from your code." Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Thanks guys for your help - I like the belt & braces approach so will be setting my objects to nothing. :)
 
I take that to be the US equivalent of "belt AND suspenders". However, it is not extra caution to set a reference to Nothing in a long lifetime object because the GC can not "collect" any object that is still referenced by a variable that is still "in scope", that is, resides in a still active object such as a "main form". Setting the reference to Nothing is the only way to have that object collected by the GC before the "main form" is closed. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
lol - yeah Belt & braces, much the same thing :) - thenks for your help so really as far as destroying objects goes - the rules I used in vb6 still appy. N
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top