Click here to Skip to main content
15,913,941 members
Home / Discussions / C#
   

C#

 
AnswerRe: Class Decleration Pin
Christian Graus30-Jan-09 18:36
protectorChristian Graus30-Jan-09 18:36 
GeneralRe: Class Decleration Pin
NazarHussain30-Jan-09 18:40
NazarHussain30-Jan-09 18:40 
GeneralRe: Class Decleration Pin
Christian Graus30-Jan-09 18:51
protectorChristian Graus30-Jan-09 18:51 
Questionproblem with threads Pin
prasadbuddhika30-Jan-09 17:28
prasadbuddhika30-Jan-09 17:28 
AnswerRe: problem with threads Pin
Christian Graus30-Jan-09 18:54
protectorChristian Graus30-Jan-09 18:54 
AnswerRe: problem with threads Pin
Najmal31-Jan-09 4:00
Najmal31-Jan-09 4:00 
QuestionAvoiding memory leaks Pin
dwolver30-Jan-09 12:16
dwolver30-Jan-09 12:16 
AnswerRe: Avoiding memory leaks Pin
Colin Angus Mackay30-Jan-09 12:29
Colin Angus Mackay30-Jan-09 12:29 
dwolver wrote:
i'm not sure how true that is and how deep it goes.


It is very true and it is very deep (but only for managed objects)


dwolver wrote:
i use this object in some button click for example, when the click is done will MyObject and all its other objects get released?


Yes, eventually. The garbage collector does not run as soon as something is no longer referenced anywhere, it runs when it needs to. And then it will clean up the objects.


dwolver wrote:
Do I need some special routine that the system will automatically call when it goes to dispose of MyObject?


Now, you've hit on the word I was going to mention next, "Dispose". If an object uses unmanaged resources then you must implement the IDisposable interface. This requires you to implement a method called Dispose() that is used to clean up the objects that the garbage collector cannot.

So, if you use unmanaged objects or another class that implements the IDisposable interface (like a file stream) then you are responsible for cleaning up the object.

You can call Dispose() manually, but a much neater solution is something like this:

using (FileStream fs = new FileStream(someFileName))
{
    // Do something with the FileStream
}


What happens here is that you tell the compiler that when you exit the using block to call Dispose on the object you created at the start. It doesn't matter how you exit the block. You can call return to exit the method as a whole, an exception can be thrown, whatever. The compiler will ensure that the object's Dispose method is called on your behalf.

* Developer Day Scotland 2 - Free community conference
* The Blog of Colin Angus Mackay


Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.

GeneralRe: Avoiding memory leaks Pin
riced31-Jan-09 5:13
riced31-Jan-09 5:13 
AnswerRe: Avoiding memory leaks Pin
Christian Graus30-Jan-09 15:39
protectorChristian Graus30-Jan-09 15:39 
AnswerRe: Avoiding memory leaks Pin
Najmal31-Jan-09 4:08
Najmal31-Jan-09 4:08 
Questioncan windows form controls as buttons and progress bars be skinned..... Pin
Mubeen.asim30-Jan-09 10:19
Mubeen.asim30-Jan-09 10:19 
AnswerRe: can windows form controls as buttons and progress bars be skinned..... Pin
Eddy Vluggen30-Jan-09 10:58
professionalEddy Vluggen30-Jan-09 10:58 
GeneralRe: can windows form controls as buttons and progress bars be skinned..... Pin
PIEBALDconsult30-Jan-09 10:59
mvePIEBALDconsult30-Jan-09 10:59 
GeneralRe: can windows form controls as buttons and progress bars be skinned..... Pin
Eddy Vluggen30-Jan-09 11:02
professionalEddy Vluggen30-Jan-09 11:02 
GeneralDataGridViewButton click event Pin
leeoze30-Jan-09 9:54
leeoze30-Jan-09 9:54 
QuestionAllowing Chinese Text in Visual Studio 05 Pin
Cozmo2330-Jan-09 7:15
Cozmo2330-Jan-09 7:15 
QuestionConnection to contactless card reader Pin
Hristiyan30-Jan-09 5:43
Hristiyan30-Jan-09 5:43 
AnswerRe: Connection to contactless card reader Pin
musefan30-Jan-09 6:07
musefan30-Jan-09 6:07 
GeneralRe: Connection to contactless card reader Pin
Hristiyan1-Feb-09 21:37
Hristiyan1-Feb-09 21:37 
Questionmodify type of dataset column Pin
pippyn30-Jan-09 4:24
pippyn30-Jan-09 4:24 
AnswerRe: modify type of dataset column Pin
howlettt30-Jan-09 4:38
howlettt30-Jan-09 4:38 
GeneralRe: modify type of dataset column Pin
pippyn30-Jan-09 5:06
pippyn30-Jan-09 5:06 
GeneralRe: modify type of dataset column Pin
howlettt30-Jan-09 6:03
howlettt30-Jan-09 6:03 
GeneralRe: modify type of dataset column Pin
pippyn30-Jan-09 6:22
pippyn30-Jan-09 6:22 

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.