Click here to Skip to main content
15,910,787 members
Home / Discussions / C#
   

C#

 
AnswerRe: odbc firebird C# Pin
Giorgi Dalakishvili5-May-09 20:03
mentorGiorgi Dalakishvili5-May-09 20:03 
QuestionEasy way to create a save/load functionality to an Application Pin
sodevrom5-May-09 13:47
sodevrom5-May-09 13:47 
AnswerRe: Easy way to create a save/load functionality to an Application Pin
Dave Kreskowiak5-May-09 17:23
mveDave Kreskowiak5-May-09 17:23 
QuestionWinForms Comboboxes Pin
Illegal Operation5-May-09 13:32
Illegal Operation5-May-09 13:32 
AnswerRe: WinForms Comboboxes Pin
dotnetmember5-May-09 16:42
dotnetmember5-May-09 16:42 
AnswerRe: WinForms Comboboxes Pin
Mycroft Holmes5-May-09 17:24
professionalMycroft Holmes5-May-09 17:24 
QuestionTo Dispose() or not Dispose(), that is the question. Pin
Peter Trevor5-May-09 13:02
Peter Trevor5-May-09 13:02 
AnswerRe: To Dispose() or not Dispose(), that is the question. Pin
Luc Pattyn5-May-09 13:25
sitebuilderLuc Pattyn5-May-09 13:25 
Hi,

it is good practice to Dispose of objects that satisfy all these conditions:
1. they have a public Dispose() method
2. you don't need them anymore
3. you did cause their creation. This includes all "new Somethings()", all "CreateXxx()" results, and some specials such as Image.FromFile(); it excludes the objects you are borrowing, such as the Graphics you get from PaintEventArgs, the Brush you get from Brushes.Black, etc. There also is no need to Dispose of Controls that reside on a Form: when the Form gets closed, the Controls get Disposed of automatically.

there are two good reasons to call Dispose explicitly:
1. the object may contain unmanaged resources (e.g. memory blocks allocated outside the CLR)
2. the object may be expensive (e.g. use lots of memory)
Disposing it explicitly does whatever is necessary to free the resources (when unmanaged) or make them collectable (when managed).

it is also common practice to Dispose in reverse order, hence a=new A(), b=new B(), b.Dispose(), a.Dispose(); this may be relevant when b actually depends on a as in b=new B(a);

it may be wise to include null tests, as in if (b!=null) b.Dispose(); in case you are not sure b really got created (say in a finally block where the try part maybe didn't complete).

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


GeneralRe: To Dispose() or not Dispose(), that is the question. Pin
fly9045-May-09 14:22
fly9045-May-09 14:22 
GeneralRe: To Dispose() or not Dispose(), that is the question. Pin
Luc Pattyn5-May-09 14:47
sitebuilderLuc Pattyn5-May-09 14:47 
JokeRe: To Dispose() or not Dispose(), that is the question. Pin
fly9045-May-09 15:24
fly9045-May-09 15:24 
GeneralRe: To Dispose() or not Dispose(), that is the question. Pin
Luc Pattyn5-May-09 15:42
sitebuilderLuc Pattyn5-May-09 15:42 
QuestionExpose Property of Constituent Control in UserControl Pin
xfitr25-May-09 11:18
xfitr25-May-09 11:18 
AnswerRe: Expose Property of Constituent Control in UserControl Pin
Christian Graus5-May-09 12:26
protectorChristian Graus5-May-09 12:26 
GeneralRe: Expose Property of Constituent Control in UserControl Pin
xfitr26-May-09 3:47
xfitr26-May-09 3:47 
JokeSolve this...... Pin
Rajdeep.NET is BACK5-May-09 9:09
Rajdeep.NET is BACK5-May-09 9:09 
GeneralRe: Solve this...... Pin
Luc Pattyn5-May-09 9:19
sitebuilderLuc Pattyn5-May-09 9:19 
GeneralRe: Solve this...... Pin
harold aptroot5-May-09 9:27
harold aptroot5-May-09 9:27 
RantRe: Solve this...... Pin
fly9045-May-09 9:25
fly9045-May-09 9:25 
GeneralRe: Solve this...... Pin
harold aptroot5-May-09 9:30
harold aptroot5-May-09 9:30 
GeneralRe: Solve this...... Pin
EliottA5-May-09 11:24
EliottA5-May-09 11:24 
GeneralRe: Solve this...... Pin
Dave Kreskowiak5-May-09 9:59
mveDave Kreskowiak5-May-09 9:59 
GeneralRe: Solve this...... Pin
CPallini5-May-09 10:53
mveCPallini5-May-09 10:53 
GeneralRe: Solve this...... Pin
Pete O'Hanlon5-May-09 11:22
mvePete O'Hanlon5-May-09 11:22 
GeneralRe: Solve this...... Pin
StarBP5-May-09 16:55
StarBP5-May-09 16:55 

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.