I know that the role of dispose function is to clear the unmanaged resources.
but according to Microsoft’s pattern ( which I understand ) they doing that :
They opened a new centralized function which takes a bool ( isDispoisng) ;
if True , so it came from dispose func ( using using or something else) – and it clears the unmanaged and managed
if false , it came from finalizer / destructor. and he kills just the unmanaged.
I dont understand why microsoft’s pattern kills also the managed if isDispoisng==True ( see the bolded words).
I thought the finilize should kill just the unmanaged….
Can you please explain ?
What did they want to achieve in this ?
Because your managed resources may hold on to other (unmanaged) resources that may need to be disposed of.
Any object that implements IDisposable should therefore be disposed by calling its Dispose method.
Edit: And indeed, event handler hookups also need to be eliminated that would otherwise prevent an object from going out of scope and being garbage collected.