DependentHandle 結構

定義

表示相依垃圾收集控制碼。 只要目標物件實例同時運作,控制碼就會有條件地讓相依物件實例保持運作,而不代表目標實例的強式參考。

public value class DependentHandle : IDisposable
public struct DependentHandle : IDisposable
type DependentHandle = struct
    interface IDisposable
Public Structure DependentHandle
Implements IDisposable
繼承
DependentHandle
實作

備註

DependentHandle具有指定物件實例作為目標的值,如果目標沒有其他強式參考,則不會讓目標保持運作,但只要目標保持運作,則相依物件實例就會這麼做。

使用此類型在概念上相當於具有指定目標物件實例 A 的弱式參考,而該物件具有欄位或屬性 (或其他一些強式參考) 相依物件實例 B。

DependentHandle 類型不是安全線程,且取用者負責確保 Dispose() 不會與其他 API 並行呼叫。 不這麼做會導致未定義的行為。

IsAllocatedTargetDependentTargetAndDependent 屬性會改為安全線程,而且如果沒有 Dispose() 同時叫用,則安全使用。

建構函式

DependentHandle(Object, Object)

使用指定的引數,初始化 結構的新實例 DependentHandle

屬性

Dependent

取得或設定目前控制碼的相依物件實例。

IsAllocated

取得值,指出這個實例是否已使用 DependentHandle(Object, Object) 建構,而且尚未處置。

Target

取得或設定目前控制碼的目標物件實例。 一旦建立實例之後, DependentHandle 目標只能設定為 null 值。 這麼做也會導致 Dependent 開始傳 null 回,而且即使先前的目標仍在運作,也有資格進行收集。

TargetAndDependent

如果可用) 為不可部分完成的作業,則取得 和 Dependent (的值 Target 。 也就是說,即使 Target 同時設定為 null ,呼叫這個方法將會同時傳回目標與相依專案,或同時傳回 null 這兩個先前的值。 如果 在此 Target 案例中循序使用 和 Dependent ,有時可以成功擷取先前的目標,但無法取得相依專案。

方法

Dispose()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。

適用於