C# disposing IDisposable

后端 未结 7 2118
滥情空心
滥情空心 2021-01-14 02:44

Could someone explain what might happen if you don\'t Dispose some IDisposable entity (by using or direct Dispose cal

7条回答
  •  遥遥无期
    2021-01-14 03:22

    One distinction that is worth pointing out is that .NET manages memory, but not resources. IDisposable is designed so that clients of classes implementing this interface can dispose resources deterministically.

    Joe Duffy states the distinction pretty clearly in his post entitled DG Update: Dispose, Finalization, and Resource Management:

    The CLR’s garbage collector (GC) does an amazing job at managing memory allocated directly to CLR objects, but was explicitly not designed to deal with unmanaged memory and OS-managed resources.

提交回复
热议问题