Edit

Share via


WeakGCHandle<T> Struct

Definition

Represents a strongly typed GC handle to a managed object.

generic <typename T>
 where T : classpublic value class WeakGCHandle : IDisposable, IEquatable<System::Runtime::InteropServices::WeakGCHandle<T>>
public struct WeakGCHandle<T> : IDisposable, IEquatable<System.Runtime.InteropServices.WeakGCHandle<T>> where T : class
type WeakGCHandle<'T (requires 'T : null)> = struct
    interface IDisposable
Public Structure WeakGCHandle(Of T)
Implements IDisposable, IEquatable(Of WeakGCHandle(Of T))

Type Parameters

T

The type of the object this WeakGCHandle<T> tracks to.

Inheritance
WeakGCHandle<T>
Implements

Remarks

The object is allowed to be collected. When the object is collected, the handle target is set to null.

This type corresponds to Weak or WeakTrackResurrection.

This type is unsafe if used incorrectly. Incorrect usage like mismanagement of lifetime, providing an invalid handle value, or concurrent disposal can result in hard to diagnose crashes or data corruptions.

.

Constructors

WeakGCHandle<T>(T, Boolean)

Initializes a new instance of WeakGCHandle<T>.

Properties

IsAllocated

Gets a value that indicates whether this handle has been allocated or not.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Equals(Object)

Indicates whether this instance and a specified object are equal.

Equals(WeakGCHandle<T>)

Indicates whether the current object is equal to another object of the same type.

FromIntPtr(IntPtr)

Returns a new WeakGCHandle<T> object created from a handle to a managed object.

GetHashCode()

Returns the hash code for the current instance.

SetTarget(T)

Sets the object this handle represents.

ToIntPtr(WeakGCHandle<T>)

Returns the internal integer representation of a WeakGCHandle<T> object.

TryGetTarget(T)

Tries to retrieve the target object that is referenced by the current WeakGCHandle<T> object.

Applies to

See also