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

C#

 
GeneralRe: Removing refrences or objects ? Garbage collector Pin
N a v a n e e t h23-Oct-07 21:21
N a v a n e e t h23-Oct-07 21:21 
GeneralRe: Removing refrences or objects ? Garbage collector Pin
lmoelleb23-Oct-07 21:27
lmoelleb23-Oct-07 21:27 
GeneralRe: Removing refrences or objects ? Garbage collector Pin
N a v a n e e t h23-Oct-07 21:32
N a v a n e e t h23-Oct-07 21:32 
GeneralRe: Removing refrences or objects ? Garbage collector Pin
lmoelleb23-Oct-07 22:45
lmoelleb23-Oct-07 22:45 
GeneralRe: Removing refrences or objects ? Garbage collector Pin
N a v a n e e t h23-Oct-07 23:01
N a v a n e e t h23-Oct-07 23:01 
GeneralRe: Removing refrences or objects ? Garbage collector Pin
Scott Dorman24-Oct-07 1:18
professionalScott Dorman24-Oct-07 1:18 
GeneralRe: Removing refrences or objects ? Garbage collector Pin
Scott Dorman24-Oct-07 1:19
professionalScott Dorman24-Oct-07 1:19 
GeneralRe: Removing refrences or objects ? Garbage collector Pin
Scott Dorman24-Oct-07 1:36
professionalScott Dorman24-Oct-07 1:36 
First, please use the <pre> tags for large code blocks like this so it keeps the formatting.

lmoelleb wrote:
To avoid confusing statements I'll just include the standard dispose pattern here.


A few points where you have really deviated from the pattern:

Your finalizer should not call Dispose, really under any circumstances. You introduce a lot of extra complexity to your resource cleanup logic by doing this and introduce a much higher chance for failure. Most of the assumptions you can make about the state of the runtime are not valid when running during finalization and most of the classes and methods are not safe to be used during finalization.

The call to GC.SupressFinalize should be in the public Dispose() method, right after the call to Dispose(true). There are probably two reasons I can give for this. One is that is simply the way the pattern is defined, which isn't an entirely helpfull answer. The other reason is that the Dispose(bool) method should be the one that encapsulates all of the cleanup logic and that this method knows wheter it is being called to do explicit cleanup or being called due to a garbage collection cycle. Because of that, the method really would need to call GC.SupressFinalize under certain conditions only. By moving the call to the public Dispose() method, those risks/concerns are removed. The ordering is still important as it ensures that GC.SupressFinalize only gets called if the Dispose operation completes successfully.

The Dispose(bool) should be protected, not private, to allow any derived classes the ability to override it.

Again, the call to GC.SupressFinalize does tell the GC that it doesn't need to finalize a second time, but this really has nothing to do with generation promotion.


Scott.

—In just two days, tomorrow will be yesterday.

[Forum Guidelines] [Articles] [Blog]

GeneralRe: Removing refrences or objects ? Garbage collector Pin
lmoelleb24-Oct-07 2:35
lmoelleb24-Oct-07 2:35 
GeneralRe: Removing refrences or objects ? Garbage collector Pin
Scott Dorman24-Oct-07 12:46
professionalScott Dorman24-Oct-07 12:46 
GeneralRe: Removing refrences or objects ? Garbage collector Pin
Scott Dorman24-Oct-07 1:22
professionalScott Dorman24-Oct-07 1:22 
Questionupdate from combobo to textbox Pin
kabutar23-Oct-07 19:54
kabutar23-Oct-07 19:54 
AnswerRe: update from combobo to textbox Pin
Christian Graus23-Oct-07 20:02
protectorChristian Graus23-Oct-07 20:02 
GeneralRe: update from combobo to textbox Pin
kabutar23-Oct-07 20:07
kabutar23-Oct-07 20:07 
Questioninsertion of nature of comment row. [modified] Pin
alok217123-Oct-07 19:43
alok217123-Oct-07 19:43 
AnswerRe: insertion of nature of comment row. Pin
Christian Graus23-Oct-07 19:51
protectorChristian Graus23-Oct-07 19:51 
AnswerRe: insertion of nature of comment row. Pin
N a v a n e e t h23-Oct-07 19:53
N a v a n e e t h23-Oct-07 19:53 
AnswerRe: insertion of nature of comment row. Pin
Guffa23-Oct-07 20:26
Guffa23-Oct-07 20:26 
QuestionHow to show current progress and progress bar..? Pin
Pankaj - Joshi23-Oct-07 19:36
Pankaj - Joshi23-Oct-07 19:36 
AnswerRe: How to show current progress and progress bar..? Pin
Christian Graus23-Oct-07 19:56
protectorChristian Graus23-Oct-07 19:56 
AnswerRe: How to show current progress and progress bar..? Pin
Abhijit Jana23-Oct-07 21:25
professionalAbhijit Jana23-Oct-07 21:25 
QuestionFinding Address of the labels back ground image Pin
sindhutiwari23-Oct-07 19:18
sindhutiwari23-Oct-07 19:18 
QuestionHow to sign digital certificate using vs.net 2005 IDE... Pin
Pankaj - Joshi23-Oct-07 18:41
Pankaj - Joshi23-Oct-07 18:41 
QuestionHow to add home page in start menu...? Pin
Pankaj - Joshi23-Oct-07 18:34
Pankaj - Joshi23-Oct-07 18:34 
AnswerRe: How to add home page in start menu...? Pin
N a v a n e e t h23-Oct-07 18:44
N a v a n e e t h23-Oct-07 18:44 

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.