|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Confused About Dispose and Finalize in VS.NetDispose/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 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 > > > > > 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 > > > >
Multithread Revisted
ulong vs UInt64 Live multi-user debugging? Help! Can I use an asterisk in the "Imports" statement? Accessing existing Excel instance CheckedListbox backcolor question File.Exists not working. Transferring data between datatables and between datareader and datatable How to use DataGridComboColumnStyle Beta Testers Needed for WindowsForms Component. |
|||||||||||||||||||||||