Zytan <(E-Mail Removed)> wrote:
> > At the end of the using block the Dispose method is called
> > which will release all unmanaged resources. It is not
> > "destructed".
>
> Ok, I am thinking that destructed = dispose. What is the difference?
> When I write a destructor, and it is run, this is the object being
> destructed, right?
Well, it's being finalized. It *could* still survive, if something
during finalization promotes it - but generally, the object is about to
be garbage collected.
Being *disposed*, however, is very different - that's just calling the
Dispose method. After Dispose has been called, an object *may* still be
perfectly usable, and disposing of it doesn't affect garbage
collection, although calling Dispose will often suppress the finalizer
if there is one (because finalizers generally do the same thing).
> http://msdn2.microsoft.com/en-us/library/yh598w02.aspx
> shows this example:
>
> Font font2 = new Font("Arial", 10.0f);
> using (font2)
> {
> // use font2
> }
>
> It seems to me that font2 can still be used after the using statement
> block. So what happens? Is the object destructed / disposed (sorry,
> I don't know the difference), and font2 = null?
font2 still refers to the same object, it's just that Dispose() has
been called on it.
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too