Home All Groups Group Topic Archive Search About

Confused About Dispose and Finalize in VS.Net

Author
5 Jul 2006 12:40 AM
eBob.com
I have a user control which creates an Excel spread sheet and badly needs
Dispose/Finalize.  I've read up on the subject in Balena and I think I
understand what is going on.  But the VS generated coded confuses me a bit.

VS generates a Dispose subroutine, but it's not obvious if it is ok to
modify it.  In the New subroutine VS makes clear that you can add code to it
and tell you where to add it ("Add any initialization after the
InitializeComponent() call").  But there is no such direction in the
generated Dispose subroutine.

VS does not generate a Finalize subroutine.  That confuses me.  Shouldn't
all controls have a Finalize method.  If I code a Finalize method (which I
should, right?) then I should also create a static "disposed"variable,
right?  That seems like the thing to do but on the other hand VS did not
generate one.

I'll be grateful if you can help me with these areas of confusion.

Bob

Author
5 Jul 2006 9:58 AM
M. Posseth
Well i believe that Francesco is pretty clear in how and when to use
Dispose/Finalize

"the Dispose/Finalize pattern should be used only when your type invokes
unmanaged code that allocates unmanaged resources (including unmanaged
memory)"

and for  detailed info see this article ( where he explains a simplified
aproach with some usefull links to detailed information )
http://www.dotnet2themax.com/blogs/fbalena/PermaLink,guid,214e65eb-7235-427f-b78d-75fc3c219c78.aspx

regards

Michel Posseth [MCP]



Show quoteHide quote
"eBob.com" wrote:

> I have a user control which creates an Excel spread sheet and badly needs
> Dispose/Finalize.  I've read up on the subject in Balena and I think I
> understand what is going on.  But the VS generated coded confuses me a bit.
>
> VS generates a Dispose subroutine, but it's not obvious if it is ok to
> modify it.  In the New subroutine VS makes clear that you can add code to it
> and tell you where to add it ("Add any initialization after the
> InitializeComponent() call").  But there is no such direction in the
> generated Dispose subroutine.
>
> VS does not generate a Finalize subroutine.  That confuses me.  Shouldn't
> all controls have a Finalize method.  If I code a Finalize method (which I
> should, right?) then I should also create a static "disposed"variable,
> right?  That seems like the thing to do but on the other hand VS did not
> generate one.
>
> I'll be grateful if you can help me with these areas of confusion.
>
> Bob
>
>
>
>
>
Author
5 Jul 2006 11:00 AM
Cor Ligthert [MVP]
eBob,

One of the goals in Net languages is to manage the finalize for you. One of
the main reasons why it is called "Managed code". (This not for C++ MFC).

I hope this helps,

Cor

Show quoteHide quote
"eBob.com" <eBob.***@totallybogus.com> schreef in bericht
news:u5JUbu8nGHA.764@TK2MSFTNGP03.phx.gbl...
>I have a user control which creates an Excel spread sheet and badly needs
>Dispose/Finalize.  I've read up on the subject in Balena and I think I
>understand what is going on.  But the VS generated coded confuses me a bit.
>
> VS generates a Dispose subroutine, but it's not obvious if it is ok to
> modify it.  In the New subroutine VS makes clear that you can add code to
> it and tell you where to add it ("Add any initialization after the
> InitializeComponent() call").  But there is no such direction in the
> generated Dispose subroutine.
>
> VS does not generate a Finalize subroutine.  That confuses me.  Shouldn't
> all controls have a Finalize method.  If I code a Finalize method (which I
> should, right?) then I should also create a static "disposed"variable,
> right?  That seems like the thing to do but on the other hand VS did not
> generate one.
>
> I'll be grateful if you can help me with these areas of confusion.
>
> Bob
>
>
>
>