GCHandleType 枚举


表示 GCHandle 类可以分配的句柄的类型。Represents the types of handles the GCHandle class can allocate.

public enum class GCHandleType
public enum GCHandleType
public enum GCHandleType
public enum GCHandleType
type GCHandleType = 
Public Enum GCHandleType


Normal 2

此句柄类型表示不透明句柄,这意味着无法通过此句柄解析固定对象的地址。This handle type represents an opaque handle, meaning you cannot resolve the address of the pinned object through the handle. 可以使用此类型跟踪对象,并防止它被垃圾回收器回收。You can use this type to track an object and prevent its collection by the garbage collector. 当非托管客户端持有对托管对象的唯一引用(从垃圾回收器检测不到该引用)时,此枚举成员很有用。This enumeration member is useful when an unmanaged client holds the only reference, which is undetectable from the garbage collector, to a managed object.

Pinned 3

此句柄类型类似于 Normal,但允许使用固定对象的地址。This handle type is similar to Normal, but allows the address of the pinned object to be taken. 这将防止垃圾回收器移动对象,因此将降低垃圾回收器的效率。This prevents the garbage collector from moving the object and hence undermines the efficiency of the garbage collector. 使用 Free() 方法可尽快释放已分配的句柄。Use the Free() method to free the allocated handle as soon as possible.

Weak 0

此句柄类型用于跟踪对象,但允许回收该对象。This handle type is used to track an object, but allow it to be collected. 当回收某个对象时,GCHandle 的内容归零。When an object is collected, the contents of the GCHandle are zeroed. 在终结器运行之前,Weak 引用归零,因此即使终结器使该对象复活,Weak 引用仍然是归零的。Weak references are zeroed before the finalizer runs, so even if the finalizer resurrects the object, the Weak reference is still zeroed.

WeakTrackResurrection 1

该句柄类型类似于 Weak,但如果对象在终结过程中复活,此句柄不归零。This handle type is similar to Weak, but the handle is not zeroed if the object is resurrected during finalization.