GCHandleType GCHandleType GCHandleType GCHandleType Enum


表示 GCHandle 類別可以配置的控制代碼的型別。Represents the types of handles the GCHandle class can allocate.

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


Normal Normal Normal 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. 當 Unmanaged 用戶端持有 Managed 物件的唯一參考,而且參考無法從記憶體回收行程偵測時,這個列舉成員就很有用。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 Pinned Pinned Pinned 3

這個控制代碼型別類似於 Normal,但是讓 Pin 物件的位址可以被取得。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 Weak Weak 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 WeakTrackResurrection WeakTrackResurrection WeakTrackResurrection 1

這個控制代碼型別和 Weak 類似,但如果物件在結束期間重新恢復的話,控制代碼不會歸零。This handle type is similar to Weak, but the handle is not zeroed if the object is resurrected during finalization.