Why call dispose(false) in the destructor?

前端 未结 6 1487
挽巷
挽巷 2020-12-12 11:33

What follows is a typical dispose pattern example:

 public bool IsDisposed { get; private set; }

  #region IDisposable Members

  public void Dispose()
  {
         


        
6条回答
  •  甜味超标
    2020-12-12 12:21

    Inside the if(disposing) you are supposed to call dispose/close on managed objects that have unmanaged resources (e.g. database connections).When the finalizer is called these objects are not longer reachable so the objects themselves can be finalized and you don't need to call dispose on them. Also the order of finalization is undeterminated so you may be calling dispose on already disposed objects.

提交回复
热议问题