Why does the traditional Dispose pattern suppress finalize?

后端 未结 6 1139
渐次进展
渐次进展 2021-01-17 22:10

Assuming this as the traditional Dispose pattern (taken from devx but seen on many websites)

class Test : IDisposable
{
  private bool isDisposed = false;

          


        
6条回答
  •  离开以前
    2021-01-17 22:58

    As noted on MSDN executing the Finalize method is costly. By calling dispose you've already self finalized your class so the finalizer doesn't need to be called. The finalizer is implemented in case the Dispose is never called directly by your code (or whoever 'owns' the instance).

提交回复
热议问题