WeakReference<T> WeakReference<T> WeakReference<T> WeakReference<T> Class

定義

表示具型別的弱式參考,即在參考物件的同時,仍允許系統透過記憶體回收來回收該物件。Represents a typed weak reference, which references an object while still allowing that object to be reclaimed by garbage collection.

generic <typename T>
 where T : classpublic ref class WeakReference sealed : System::Runtime::Serialization::ISerializable
[System.Serializable]
public sealed class WeakReference<T> : System.Runtime.Serialization.ISerializable where T : class
type WeakReference<'T (requires 'T : null)> = class
    interface ISerializable
Public NotInheritable Class WeakReference(Of T)
Implements ISerializable

類型參數

T

參考的物件型別。The type of the object referenced.

繼承
WeakReference<T>WeakReference<T>WeakReference<T>WeakReference<T>
屬性
實作

備註

弱式參考可讓記憶體回收行程回收物件,同時仍然允許應用程式存取的物件。A weak reference enables the garbage collector to collect an object while still allowing an application to access the object. 如果您需要物件時,您可以取得它的強式參考,並避免其所收集。If you need the object, you can obtain a strong reference to it and prevent it from being collected.

建構函式

WeakReference<T>(T) WeakReference<T>(T) WeakReference<T>(T) WeakReference<T>(T)

初始化 WeakReference<T> 類別的新執行個體,這個類別會參考指定的物件。Initializes a new instance of the WeakReference<T> class that references the specified object.

WeakReference<T>(T, Boolean) WeakReference<T>(T, Boolean) WeakReference<T>(T, Boolean) WeakReference<T>(T, Boolean)

初始化 WeakReference<T> 類別的新執行個體,此類別會參考指定的物件,並使用指定的重新恢復狀態追蹤。Initializes a new instance of the WeakReference<T> class that references the specified object and uses the specified resurrection tracking.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

捨棄對目前 WeakReference<T> 物件所表示之目標的參考。Discards the reference to the target that is represented by the current WeakReference<T> object.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

將序列化目前 SerializationInfo 物件所需的所有資料填入 WeakReference<T> 物件。Populates a SerializationInfo object with all the data necessary to serialize the current WeakReference<T> object.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
SetTarget(T) SetTarget(T) SetTarget(T) SetTarget(T)

設定這個 WeakReference<T> 物件所參考的目標物件。Sets the target object that is referenced by this WeakReference<T> object.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)
TryGetTarget(T) TryGetTarget(T) TryGetTarget(T) TryGetTarget(T)

嘗試擷取目前 WeakReference<T> 物件所參考的目標物件。Tries to retrieve the target object that is referenced by the current WeakReference<T> object.

適用於