ThreadLocal<T>.Dispose 方法

定義

釋放這個 ThreadLocal<T> 執行個體所使用的資源。Releases the resources used by this ThreadLocal<T> instance.

多載

Dispose()

釋放 ThreadLocal<T> 類別目前的執行個體所使用的全部資源。Releases all resources used by the current instance of the ThreadLocal<T> class.

Dispose(Boolean)

釋放這個 ThreadLocal<T> 執行個體所使用的資源。Releases the resources used by this ThreadLocal<T> instance.

Dispose()

釋放 ThreadLocal<T> 類別目前的執行個體所使用的全部資源。Releases all resources used by the current instance of the ThreadLocal<T> class.

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

實作

備註

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

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

注意

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

另請參閱

Dispose(Boolean)

釋放這個 ThreadLocal<T> 執行個體所使用的資源。Releases the resources used by this ThreadLocal<T> instance.

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

布林值,表示是否會因為呼叫 Dispose() 而呼叫這個方法。A Boolean value that indicates whether this method is being called due to a call to Dispose().

備註

不同于大多數 ThreadLocal<T> 的成員,這個方法不是安全線程。Unlike most of the members of ThreadLocal<T>, this method is not thread-safe.

另請參閱

適用於