Confused About Dispose and Finalize in VS.Net

E

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
 
G

Guest

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]
 
C

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top