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

C#

 
GeneralRe: C# Developer looking for a new project Pin
Liam Cairns Kelly5-Aug-12 5:13
Liam Cairns Kelly5-Aug-12 5:13 
GeneralRe: C# Developer looking for a new project Pin
jschell5-Aug-12 7:56
jschell5-Aug-12 7:56 
QuestionC# 2010 change linq to sql Pin
dcof4-Aug-12 11:03
dcof4-Aug-12 11:03 
Questiondispose (always?) Pin
thewazz4-Aug-12 7:46
professionalthewazz4-Aug-12 7:46 
GeneralRe: dispose (always?) Pin
PIEBALDconsult4-Aug-12 8:25
mvePIEBALDconsult4-Aug-12 8:25 
GeneralRe: dispose (always?) Pin
OriginalGriff5-Aug-12 22:18
mveOriginalGriff5-Aug-12 22:18 
AnswerRe: dispose (always?) Pin
Ed Hill _5_5-Aug-12 22:12
Ed Hill _5_5-Aug-12 22:12 
AnswerRe: dispose (always?) Pin
OriginalGriff5-Aug-12 22:18
mveOriginalGriff5-Aug-12 22:18 
As PIEBALDconsult said: if you create it, you should dispose it when you are finished with it.

The problem is that some objects use scarce resources, and unless they are disposed those resources do not become available for other classes within your app, or other applications until the Garbage Collector identifies them as unused, or the app ends. Since this may not happen for minutes, days, or even months, it is a very good idea to get into the habit of Disposing everything which implements IDispose. This is particularly true of SQL components, Graphics releted items, and files.
You may not notice a problem, but it is potentially there to bite you in production, and extremely difficult to track down and fix - since all you get is normally "out of memory" errors, with no indication of what caused it.

The easiest and cleanest way if to wrap the object in a using block as this also takes the object out of scope when it is Disposed, so that it cannot be accidentally referenced later.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

AnswerRe: dispose (always?) Pin
BobJanova5-Aug-12 23:49
BobJanova5-Aug-12 23:49 
GeneralRe: dispose (always?) Pin
PIEBALDconsult6-Aug-12 3:50
mvePIEBALDconsult6-Aug-12 3:50 
GeneralRe: dispose (always?) Pin
BobJanova7-Aug-12 0:26
BobJanova7-Aug-12 0:26 
GeneralRe: dispose (always?) Pin
PIEBALDconsult7-Aug-12 3:36
mvePIEBALDconsult7-Aug-12 3:36 
GeneralRe: dispose (always?) Pin
thewazz7-Aug-12 4:58
professionalthewazz7-Aug-12 4:58 
GeneralRe: dispose (always?) Pin
Pete O'Hanlon7-Aug-12 23:43
mvePete O'Hanlon7-Aug-12 23:43 
GeneralRe: dispose (always?) Pin
jschell10-Aug-12 12:42
jschell10-Aug-12 12:42 
GeneralRe: dispose (always?) Pin
PIEBALDconsult10-Aug-12 13:38
mvePIEBALDconsult10-Aug-12 13:38 
GeneralRe: dispose (always?) Pin
jschell11-Aug-12 7:28
jschell11-Aug-12 7:28 
GeneralRe: dispose (always?) Pin
PIEBALDconsult11-Aug-12 12:05
mvePIEBALDconsult11-Aug-12 12:05 
QuestionC# setup and deployment projects Pin
Zeyad Jalil4-Aug-12 3:26
professionalZeyad Jalil4-Aug-12 3:26 
AnswerRe: C# setup and deployment projects Pin
jschell4-Aug-12 7:00
jschell4-Aug-12 7:00 
QuestionRe: C# setup and deployment projects Pin
Zeyad Jalil4-Aug-12 20:12
professionalZeyad Jalil4-Aug-12 20:12 
AnswerRe: C# setup and deployment projects Pin
jschell5-Aug-12 7:26
jschell5-Aug-12 7:26 
AnswerRe: C# setup and deployment projects Pin
Paul Conrad4-Aug-12 11:47
professionalPaul Conrad4-Aug-12 11:47 
AnswerRe: C# setup and deployment projects Pin
Bernhard Hiller5-Aug-12 22:26
Bernhard Hiller5-Aug-12 22:26 
GeneralRe: C# setup and deployment projects Pin
Zeyad Jalil7-Aug-12 20:52
professionalZeyad Jalil7-Aug-12 20:52 

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.