Click here to Skip to main content
12,348,995 members (63,773 online)
   

C#

 
AnswerRe: C++ virtual destructor in C#? Why not? Pin
Mark Salsbery16-May-09 6:41
mvpMark Salsbery16-May-09 6:41 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
devvvy16-May-09 8:02
memberdevvvy16-May-09 8:02 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
Mark Salsbery16-May-09 8:08
mvpMark Salsbery16-May-09 8:08 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
devvvy16-May-09 8:10
memberdevvvy16-May-09 8:10 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
Mark Salsbery16-May-09 8:17
mvpMark Salsbery16-May-09 8:17 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
S. Senthil Kumar16-May-09 9:08
memberS. Senthil Kumar16-May-09 9:08 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
Mark Salsbery16-May-09 9:20
mvpMark Salsbery16-May-09 9:20 
AnswerRe: C++ virtual destructor in C#? Why not? Pin
Guffa16-May-09 16:46
mvpGuffa16-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
memberdevvvy16-May-09 17:04 
GeneralRe: C++ virtual destructor in C#? Why not? Pin
Guffa22-May-09 13:27
mvpGuffa22-May-09 13:27 
QuestionUse methods from another form Pin
michaelgr116-May-09 2:08
membermichaelgr116-May-09 2:08 
AnswerRe: Use methods from another form Pin
OriginalGriff16-May-09 2:39
memberOriginalGriff16-May-09 2:39 
AnswerRe: Use methods from another form Pin
michaelgr116-May-09 3:03
membermichaelgr116-May-09 3:03 
GeneralRe: Use methods from another form Pin
OriginalGriff16-May-09 3:53
memberOriginalGriff16-May-09 3:53 
AnswerRe: Use methods from another form Pin
Manas Bhardwaj16-May-09 6:20
memberManas Bhardwaj16-May-09 6:20 
GeneralRe: Use methods from another form Pin
michaelgr116-May-09 6:33
membermichaelgr116-May-09 6:33 
GeneralRe: Use methods from another form Pin
Dave Kreskowiak16-May-09 17:24
mvpDave Kreskowiak16-May-09 17:24 
QuestionDataGridView CellPainting Performance Issue Pin
John Jak16-May-09 2:08
memberJohn Jak16-May-09 2:08 
QuestionOCR using Abby Finereader in C# Pin
makimca16-May-09 1:33
membermakimca16-May-09 1:33 
AnswerRe: OCR using Abby Finereader in C# Pin
incaunu16-Jul-09 3:20
memberincaunu16-Jul-09 3:20 
AnswerRe: OCR using Abby Finereader in C# Pin
shparmar17-Nov-10 23:03
membershparmar17-Nov-10 23:03 
Questiongraph Pin
shanmugam_1316-May-09 0:45
membershanmugam_1316-May-09 0:45 
AnswerRe: graph Pin
Rajesh R Subramanian16-May-09 1:16
mvpRajesh R Subramanian16-May-09 1:16 
GeneralRe: graph Pin
Manas Bhardwaj16-May-09 6:23
memberManas Bhardwaj16-May-09 6:23 
GeneralRe: graph Pin
Rajesh R Subramanian16-May-09 19:11
mvpRajesh 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.


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 24 Jun 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid