DependentHandle Struct
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a dependent garbage-collection handle. The handle will conditionally keep a dependent object instance alive as long as a target object instance is alive as well, without representing a strong reference to the target instance.
public value class DependentHandle : IDisposable
public struct DependentHandle : IDisposable
type DependentHandle = struct
interface IDisposable
Public Structure DependentHandle
Implements IDisposable
- Inheritance
- Implements
Remarks
A DependentHandle value with a given object instance as target will not cause the target to be kept alive if there are no other strong references to it, but it will do so for the dependent object instance as long as the target is alive.
Using this type is conceptually equivalent to having a weak reference to a given target object instance A, with that object having a field or property (or some other strong reference) to a dependent object instance B.
The DependentHandle type is not thread-safe, and consumers are responsible for ensuring that Dispose() is not called concurrently with other APIs. Not doing so results in undefined behavior.
The IsAllocated, Target, Dependent, and TargetAndDependent properties are instead thread-safe, and safe to use if Dispose() is not concurrently invoked as well.
Constructors
DependentHandle(Object, Object) |
Initializes a new instance of the DependentHandle struct with the specified arguments. |
Properties
Dependent |
Gets or sets the dependent object instance for the current handle. |
IsAllocated |
Gets a value indicating whether this instance was constructed with DependentHandle(Object, Object) and has not yet been disposed. |
Target |
Gets or sets the target object instance for the current handle. The target can only be set to a |
TargetAndDependent |
Gets the values of both Target and Dependent (if available) as an atomic operation.
That is, even if Target is concurrently set to |
Methods
Dispose() |
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |