TextReader.Dispose 方法

定義

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

多載

Dispose()

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

Dispose(Boolean)

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

Dispose()

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

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

實作

備註

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

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

注意

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

Dispose(Boolean)

釋放 TextReader 所使用的 unmanaged 資源並選擇性地釋放 managed 的資源。Releases the unmanaged resources used by the TextReader 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

若為 true,則會同時釋放 Managed 與 Unmanaged 資源;若為 false,則只釋放 Unmanaged 資源。true to release both managed and unmanaged resources; false to release only unmanaged resources.

備註

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

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

給繼承者的注意事項

Dispose 可以被其他物件呼叫多次。 Dispose 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).

另請參閱

適用於