473,770 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confused About Dispose and Finalize in VS.Net

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
InitializeCompo nent() 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"varia ble,
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


Jul 5 '06 #1
2 1296
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/f...c3c219c78.aspx

regards

Michel Posseth [MCP]

"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
InitializeCompo nent() 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"varia ble,
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


Jul 5 '06 #2
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

"eBob.com" <eB******@total lybogus.comschr eef in bericht
news:u5******** *****@TK2MSFTNG P03.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
InitializeCompo nent() 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"varia ble,
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


Jul 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1933
by: RiteshDotNet | last post by:
..net Frame work 1. Dispose Method what it does ? A. who its call / when it calls ? B. Is it fire automatically ? c. When dispose method is call what it does ? D. Release a Object from memory or release refrence from memory ? E. If it release object from memory then what GC does ? 2. Which class can have dispose method ? class which is member of IDispose Inteface 3. Where we should use abstract / Interface ?
4
5075
by: Joe Abou Jaoude | last post by:
I m preparing to pass the 70-306 exam, so i downloaded Q & A from multiple sites. There's this question that really confuses me, coz i see that both answers A and C are both correct. Can anyone help me to pick the right answer and explain me why ? thx. Your development team creates an order entry application by using Visual Studio .NET. The application stores and retrieves data in a
156
5905
by: Dennis | last post by:
Ok, I'm trying to dispose of every object that I create that has a dispose method based on advice from this newsgroup. However, I'm not sure how to dispose of the following object that was created inside a method call. dim myvar as new object1 object1.dosomethingmethod(new object2) Note that object 2 has a dispose method but how do I dispose of it unless I do the following:
4
271
by: RiteshDotNet | last post by:
..net Frame work 1. Dispose Method what it does ? A. who its call / when it calls ? B. Is it fire automatically ? c. When dispose method is call what it does ? D. Release a Object from memory or release refrence from memory ? E. If it release object from memory then what GC does ? 2. Which class can have dispose method ? class which is member of IDispose Inteface 3. Where we should use abstract / Interface ?
0
9432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.