Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
GeneralRe: Dispose Method Pin
Guffa2-Aug-07 7:47
Guffa2-Aug-07 7:47 
GeneralRe: Dispose Method Pin
Luc Pattyn2-Aug-07 8:23
sitebuilderLuc Pattyn2-Aug-07 8:23 
GeneralRe: Dispose Method Pin
Guffa4-Aug-07 1:08
Guffa4-Aug-07 1:08 
GeneralRe: Dispose Method [modified] Pin
Luc Pattyn4-Aug-07 14:48
sitebuilderLuc Pattyn4-Aug-07 14:48 
GeneralRe: Dispose Method Pin
Luc Pattyn2-Aug-07 21:56
sitebuilderLuc Pattyn2-Aug-07 21:56 
GeneralRe: Dispose Method Pin
Guffa4-Aug-07 1:19
Guffa4-Aug-07 1:19 
AnswerRe: Dispose Method Pin
Karthi_jpk30-Jul-07 3:19
Karthi_jpk30-Jul-07 3:19 
AnswerRe: Dispose Method Pin
Scott Dorman31-Jul-07 14:29
professionalScott Dorman31-Jul-07 14:29 
Even though you may be using only managed code, many of the base classes in .NET use the Win32 API and other unmanaged code internally. The Dispose method is used by the GC to know how to clean up that unmanaged memory.

As far as using (calling) Dispose, it can be safely assumed to be a best practice that if the class implements Dispose (or the IDisposable interface, then you should call the Dispose method when you are done using the class. This is most easily accomplished by the using statement, which defines a scope, outside of which an object or objects will be disposed.
C#
using (Font font1 = new Font("Arial", 10.0f))
If you are writing your own classes, you want to implement IDisposable if

1. you have unmanaged resources that you are working with internally
2. any class in your inheritance chain implements IDisposable
3. you want to explicitly manage the lifetime of the class

You can check out the following references for more information:

Implementing IDisposable and the Dispose Pattern Properly[^]
Using Garbage Collection in .NET[^]

-----------------------------
In just two days, tomorrow will be yesterday.

http://geekswithblogs.net/sdorman

GeneralRe: Dispose Method Pin
N a v a n e e t h31-Jul-07 18:21
N a v a n e e t h31-Jul-07 18:21 
GeneralRe: Dispose Method Pin
Scott Dorman31-Jul-07 19:43
professionalScott Dorman31-Jul-07 19:43 
QuestionConnecting to SQL Server through C#.net Pin
Saba0230-Jul-07 2:32
Saba0230-Jul-07 2:32 
AnswerRe: Connecting to SQL Server through C#.net Pin
originSH30-Jul-07 3:03
originSH30-Jul-07 3:03 
AnswerRe: Connecting to SQL Server through C#.net Pin
Karthi_jpk30-Jul-07 3:04
Karthi_jpk30-Jul-07 3:04 
GeneralRe: Connecting to SQL Server through C#.net [modified] Pin
originSH30-Jul-07 3:19
originSH30-Jul-07 3:19 
QuestionAnother instance of my program is already running? Pin
pmartike30-Jul-07 2:17
pmartike30-Jul-07 2:17 
AnswerRe: Another instance of my program is already running? [modified] Pin
Martin#30-Jul-07 2:22
Martin#30-Jul-07 2:22 
QuestionSMO Impersonation? Pin
NanaAM30-Jul-07 1:47
NanaAM30-Jul-07 1:47 
QuestionSir Who redirect Fonts from C:\WINDOWS\Fonts to my Sample Application ? Pin
CodeVarma30-Jul-07 1:37
CodeVarma30-Jul-07 1:37 
QuestionConverting numbers and run some math equations in C# Pin
guyav9930-Jul-07 1:36
guyav9930-Jul-07 1:36 
AnswerRe: Converting numbers and run some math equations in C# Pin
User 665830-Jul-07 1:49
User 665830-Jul-07 1:49 
GeneralRe: Converting numbers and run some math equations in C# Pin
guyav9930-Jul-07 1:51
guyav9930-Jul-07 1:51 
GeneralRe: Converting numbers and run some math equations in C# Pin
User 665830-Jul-07 1:57
User 665830-Jul-07 1:57 
AnswerRe: Converting numbers and run some math equations in C# Pin
Guffa30-Jul-07 1:58
Guffa30-Jul-07 1:58 
GeneralRe: Converting numbers and run some math equations in C# Pin
guyav9930-Jul-07 2:04
guyav9930-Jul-07 2:04 
AnswerRe: Converting numbers and run some math equations in C# Pin
Guffa30-Jul-07 2:14
Guffa30-Jul-07 2:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.