unsure of what I'm doing & need info

  • Thread starter Thread starter Smitty
  • Start date Start date
S

Smitty

Been messing with vb6 for awhile, but am unfamiliar with 2005 & oop.

in a sub i'm using dim mydialog as openfiledialog
and the rest of the code follows.

everything works fine on the surface but....

My question is...should I use mydialog.dispose() before
exiting the sub, or will vb take care of this for me.
 
My question is...should I use mydialog.dispose() before
exiting the sub, or will vb take care of this for me.

..NET is a managed environment and most of the time you do not need to call
dispose.

Some people like to call it regardless.

In anycase, best to check the class documentation to see if .dispose is
required.
 
Smitty said:
in a sub i'm using dim mydialog as openfiledialog and the rest of the code
follows.
everything works fine on the surface but....
My question is...should I use mydialog.dispose() before exiting the sub,
or will vb take care of this for me.

If you are showing the form by calling its 'ShowDialog' method, the form
doesn't get disposed automatically. Thus I'd recommend to dispose it by
hand. This can be done using a 'Using' block, which will guarantee that
'Dispose' is called:

\\\
Using f As New FooForm()
If f.ShowDialog() = ... Then
...
Else
...
End If
End Using
///
 
Herfried said:
If you are showing the form by calling its 'ShowDialog' method, the form
doesn't get disposed automatically. Thus I'd recommend to dispose it by
hand. This can be done using a 'Using' block, which will guarantee that
'Dispose' is called:


And what about using me.dispose() method into the btnClose_Click of the
dialog form?

Marco / iw2nzm
 
Marco,

At the end of a manageged code class. Do nothing.

This does not mean that you don't see everything anymore it is done in its
best time.

Cor
 
Marco Trapanese said:
And what about using me.dispose() method into the btnClose_Click of the
dialog form?

It's not necessary here. Simply follow the pattern I have shown.
 
Smitty said:
in a sub i'm using dim mydialog as openfiledialog and the rest of the
code follows.
everything works fine on the surface but....

Does openfiledialog have a Close() method?
If so call it, then check the documentation for that method as to
whether it calls Dispose for you.

Failing that ...

Does openfiledialog have a Dispose() method?
If so, call it.

The *convention* is that the Dispose method should release any
/unmanaged/ resources that the class makes use of. If you don't call
Dispose, then the chances are it will get called for you when the object
gets "Finalized", but that may not happen for quite some time (possibly
not until the entire process ends).

So - yes, I'd say you probably /ought/ to but, if Our Friends in Redmond
have done their jobs right, it shouldn't make any difference.

HTH,
Phill W.
 
Back
Top