With this you are saying in my opinon that it is needed to control yoursel
all managed resources because the Microsoft managed code is not save
This is not true. By implementing IDispose a developer's intent is to give a user a way to clean up the object immediately and not wait for GC, and usually for a specific reason. That waiting for the GC to clean up this object may have side effects. Two side effects are needless code execution while the object is waiting to be cleaned up (which is why dataview implements IDispose by the way) and deterministic memory release. Also if the object implements the finalize method it can be about improving the GC performance also
The same as checking if a calculation is done right, afterwards,
Not its not. That has nothing to do with IDispose. IDispose is about avoiding non-deterministic clean up and avoiding side effects. Your example has nothing to do with either of those
I have more trust than you in the code from Microsof
Its not about GC trust. I know the object will be cleaned up sometime, but in the mean time the object may be repsonding to events and doing processing, it may be holding onto valuable resources, you don't know what the object may be doing
You know why dataview calls dispose? Because there is a member that has registered to ~6 events in the datatable and that member also hands its reference off to the datatable for who knows what but probably for callbacks. So while the dataview is waiting to be cleaned up, that dataview and its member may be responding to events from the datatable and doing needless processing. So which is worse? Needlessly responding to these events while waiting to be cleaned up, or calling IDispose and incur the unregistering events code hit up front? This needless reponding to events may not be just about extra processing but actual bugs. I have seen code where the developer thinks the object is dead but is still responding to events and executing code that had no right to still be executing
only will check when there is a bu
Talk about bad programming practice. I pray that you are not developing air traffic control systems or banking software
From my view there are three approaches to take. Always call dispose, always wait and let the GC clean up, or approach each dispose situation individually and examine the IL source/source/profile(if you don't have the code) to see if you should call dispose or not in the specific situation.
If you always wait for the GC, bugs can and will arise in your code, thats a fact just read the newsgroups for awhile. Not calling dispose leaves a large unknown in your code and that is dangerous. Knowing this but still not calling dispose and putting this code in release is BAD programming and unacceptable
If you always call IDispose you incur some overhead upfront but that overhead would be done anyways later on. You also remove that unknown I mentioned earlier. Also if the object implements the finalize method then calling dispose can have a positive performance impact on the GC during cleanup.
The last choice is probably good for any developer who wants to know exactly whats going on at every step in their code, and wiegh the consequences of not calling Dispose upfront. But even if you know whats going on in this version of the code, how do you know it will be the same in the next version. This programming decision can become a maintainence nightmare and can cause bugs in future versions
So when it comes down to it I vote for calling dispose regardless