Click here to Skip to main content
15,881,882 members
Home / Discussions / C#
   

C#

 
AnswerRe: C++ virtual destructor in C#? Why not? Pin
Mark Salsbery16-May-09 6:41
Mark Salsbery16-May-09 6:41 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
devvvy16-May-09 8:02
devvvy16-May-09 8:02 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
Mark Salsbery16-May-09 8:08
Mark Salsbery16-May-09 8:08 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
devvvy16-May-09 8:10
devvvy16-May-09 8:10 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
Mark Salsbery16-May-09 8:17
Mark Salsbery16-May-09 8:17 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
S. Senthil Kumar16-May-09 9:08
S. Senthil Kumar16-May-09 9:08 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
Mark Salsbery16-May-09 9:20
Mark Salsbery16-May-09 9:20 
AnswerRe: C++ virtual destructor in C#? Why not? Pin
Guffa16-May-09 16:46
Guffa16-May-09 16:46 
devvvy wrote:
Managed memory is freed by call to Dispose


No. This is the main difference for a memory management system that has a garbage collector: It's the garbage collection that frees all managed memory, that can not be done any other way. The garbage collector removes any objects that has no references to it, so to get an object collected you just make sure that there is no reference to it.

If an object has no references to it, the references that it contains are not considered as active by the garbage collector. Therefore, if an ojbect only references managed objects (that don't implement IDisposable), you don't have to do anything at all when releasing the object. At the moment when the object is up for garbage collection, all it's child objects are automatically up for garbage collection (unless they are also referenced from some other object).

There is no destructor in C#, like there is in C++. There is no reference counting going on, so at the moment when you remove the last reference to an object, nothing happens. When the garbage collector notices that the object can be collected, but it has a finalizer method (that uses the same syntax as a destructor in C++), the object placed in the finalizing queue. A background thread is working the queue, calling the finalizer method of each object, and after that the object is a regular managed object that the garbage collector can remove.

The finalizer method is only used as a backup for when the Dispose method is not called properly. The Dispose method is the normal means of controlling the life cycle of an object.

Despite everything, the person most likely to be fooling you next is yourself.

GeneralRe: C++ virtual destructor in C#? Why not? Pin
devvvy16-May-09 17:04
devvvy16-May-09 17:04 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
Guffa22-May-09 13:27
Guffa22-May-09 13:27 
QuestionUse methods from another form Pin
michaelgr116-May-09 2:08
michaelgr116-May-09 2:08 
AnswerRe: Use methods from another form Pin
OriginalGriff16-May-09 2:39
mveOriginalGriff16-May-09 2:39 
AnswerRe: Use methods from another form Pin
michaelgr116-May-09 3:03
michaelgr116-May-09 3:03 
GeneralRe: Use methods from another form Pin
OriginalGriff16-May-09 3:53
mveOriginalGriff16-May-09 3:53 
AnswerRe: Use methods from another form Pin
Manas Bhardwaj16-May-09 6:20
professionalManas Bhardwaj16-May-09 6:20 
GeneralRe: Use methods from another form Pin
michaelgr116-May-09 6:33
michaelgr116-May-09 6:33 
GeneralRe: Use methods from another form Pin
Dave Kreskowiak16-May-09 17:24
mveDave Kreskowiak16-May-09 17:24 
QuestionDataGridView CellPainting Performance Issue Pin
John Jak16-May-09 2:08
John Jak16-May-09 2:08 
QuestionOCR using Abby Finereader in C# Pin
makimca16-May-09 1:33
makimca16-May-09 1:33 
AnswerRe: OCR using Abby Finereader in C# Pin
incaunu16-Jul-09 3:20
incaunu16-Jul-09 3:20 
AnswerRe: OCR using Abby Finereader in C# Pin
shparmar17-Nov-10 23:03
shparmar17-Nov-10 23:03 
Questiongraph Pin
shanmugam_1316-May-09 0:45
shanmugam_1316-May-09 0:45 
AnswerRe: graph Pin
Rajesh R Subramanian16-May-09 1:16
professionalRajesh R Subramanian16-May-09 1:16 
GeneralRe: graph Pin
Manas Bhardwaj16-May-09 6:23
professionalManas Bhardwaj16-May-09 6:23 
GeneralRe: graph Pin
Rajesh R Subramanian16-May-09 19:11
professionalRajesh R Subramanian16-May-09 19:11 

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.