Purpose of Dispose calling Dispose(IsDisposing) pattern in C#?

后端 未结 4 1528
清歌不尽
清歌不尽 2020-12-16 04:18

Here is code from MSDN. I don\'t understand why the work isn\'t just done in the regular Dispose() method here. What is the purpose of having the Dispose(bool) method? Wh

4条回答
  •  失恋的感觉
    2020-12-16 05:11

    Regarding the answer,

    Your Dispose(disposing) method shouldn't explicitly free resources if it is called from finalizer, since these resources can be already freed by GC.

    It's missing an important word. This should really say:

    Your Dispose(disposing) method shouldn't explicitly free finalizable (i.e. managed) resources if it is called from finalizer, since these resources can be already freed by GC. Only native resources should be released in a Finalizer.

    I'm pretty sure that the poster meant this but just wasn't explicit enough in the post : )

提交回复
热议问题