TextWriter.Dispose TextWriter.Dispose TextWriter.Dispose TextWriter.Dispose Method

定義

釋放由 TextWriter 物件使用的所有資源。Releases all resources used by the TextWriter object.

多載

Dispose() Dispose() Dispose() Dispose()

釋放由 TextWriter 物件使用的所有資源。Releases all resources used by the TextWriter object.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放 TextWriter 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the TextWriter and optionally releases the managed resources.

Dispose() Dispose() Dispose() Dispose()

釋放由 TextWriter 物件使用的所有資源。Releases all resources used by the TextWriter object.

public:
 virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()

實作

備註

Dispose 使用完畢時,請呼叫 TextWriterCall Dispose when you are finished using the TextWriter. Dispose 方法會將 TextWriter 保留在無法使用的狀態。The Dispose method leaves the TextWriter in an unusable state. 呼叫Dispose之後,您必須釋放所有對的TextWriter參考,讓垃圾收集行程可以TextWriter回收所佔用的記憶體。After calling Dispose, you must release all references to the TextWriter so the garbage collector can reclaim the memory that the TextWriter was occupying.

如需詳細資訊,請參閱清除非受控資源執行 Dispose 方法For more information, see Cleaning Up Unmanaged Resources and Implementing a Dispose Method.

注意在您Dispose釋放最後一個參考TextWriter之前,請一律呼叫。Note Always call Dispose before you release your last reference to the TextWriter. 否則工作窗格所使用的資源不會釋放,直到記憶體回收行程呼叫 TextWriter 物件的 Finalize 方法。Otherwise, the resources it is using will not be freed until the garbage collector calls the TextWriter object's Finalize method.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放 TextWriter 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the TextWriter and optionally releases the managed resources.

protected:
 virtual void Dispose(bool disposing);
protected virtual void Dispose (bool disposing);
abstract member Dispose : bool -> unit
override this.Dispose : bool -> unit
Protected Overridable Sub Dispose (disposing As Boolean)

參數

disposing
Boolean Boolean Boolean Boolean

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

備註

這個方法是由DisposeFinalize所呼叫。This method is called by Dispose and Finalize. 根據預設,這個方法會將disposing參數指定true為。By default, this method specifies the disposing parameter as true. Finalizedisposing參數指定為falseFinalize specifies the disposing parameter as false.

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

給繼承者的注意事項

Dispose(Boolean) 可以被其他物件呼叫多次。 Dispose(Boolean) can be called multiple times by other objects. 覆寫這個方法時,請小心不要參考先前已在先前的呼叫Dispose中處置過的物件。When overriding this method, be careful not to reference objects that have been previously disposed of in an earlier call to Dispose. 如需如何執行這個方法的詳細資訊,請參閱[執行 Dispose 方法](~/docs/standard/garbage-collection/implementing-dispose.md)。For more information about how to implement this method, see [Implementing a Dispose Method](~/docs/standard/garbage-collection/implementing-dispose.md). 如需Dispose()Finalize()的詳細資訊, 請參閱[清除非受控資源](~/docs/standard/garbage-collection/unmanaged.md)。For more information about Dispose() and Finalize(), see [Cleaning Up Unmanaged Resources](~/docs/standard/garbage-collection/unmanaged.md).
另請參閱

適用於