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

后端 未结 4 1539
清歌不尽
清歌不尽 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 04:50

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

    So, Dispose(disposing) should check whether it was called manually or from GC and acts appopriately.

提交回复
热议问题