Control.Dispose(Boolean) 方法


釋放 Control 所使用的 Unmanaged 資源,以及其子系的控制項,並會選擇性地釋放一些 Managed 資源。Releases the unmanaged resources used by the Control and its child controls and optionally releases the managed resources.

 override void Dispose(bool disposing);
protected override void Dispose (bool disposing);
override this.Dispose : bool -> unit
Protected Overrides Sub Dispose (disposing As Boolean)



true 表示釋放 Managed 和 Unmanaged 資源,false 則表示只釋放 Unmanaged 資源。true to release both managed and unmanaged resources; false to release only unmanaged resources.


這個方法是由公用 Dispose() 方法和 Finalize 方法所呼叫。Dispose()This method is called by the public Dispose() method and the Finalize method.Dispose() 使用設定為 truedisposing 參數,叫用受保護的 Dispose(Boolean) 方法。invokes the protected Dispose(Boolean) method with the disposing parameter set to true. Finalize 會叫用 disposing 設定為 falseDisposeFinalize invokes Dispose with disposing set to false.

disposing 參數為 true 時,這個方法會釋放 Control 參考的任何 Managed 物件所掌握的資源。When the disposing parameter is true, this method releases all resources held by any managed objects that this Control references. 這個方法會叫用每個參考物件的 Dispose() 方法。This method invokes the Dispose() method of each referenced object.


Dispose 可以被其他物件呼叫多次。 Dispose can be called multiple times by other objects. 覆寫 Dispose(Boolean) 請小心,不要參考先前已在先前的呼叫 Dispose中處置的物件。When overriding Dispose(Boolean) be careful not to reference objects that have been previously disposed of in an earlier call to Dispose. 如需如何執行 Dispose(Boolean)的詳細資訊,請參閱[執行 Dispose 方法](/dotnet/standard/garbage-collection/implementing-dispose)。For more information about how to implement Dispose(Boolean), see [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose).

如需 DisposeFinalize()的詳細資訊,請參閱清除非受控資源和覆寫 Finalize 方法For more information about Dispose and Finalize(), see Cleaning Up Unmanaged Resources and Overriding the Finalize Method.