C# knowledge series: the role of GCHandleType

to sum up:

        Normal: The object is marked as completely unmanaged by the GC, but the memory location will be moved by the GC. We need to manually call Free to release the corresponding GC object

        Pinned: The object is marked as a state that is not managed by the GC at all, and the memory address is not reclaimed by the GC or moved by the GC. We need to manually call Free to release the corresponding GC object

        Weak: If the object is marked as "unreachable" (not used by any object and needs to be cleared) (but the memory of the object has not been actually recycled), the object pointed to by Weak will be marked as null; no We need to manually call Free to release the corresponding GC object

        WeakTrackResurrection: If the object is restored to the state during the final processing, the control code is not reset; that is, only the GC object is eventually recycled. Before that, we can get the actual object through Handle, and we don’t need to manually call Free to release the corresponding GC object

 

reference:

        GCHandleType Enum

        c#-GCHandle: When to use GCHandleType.Normal explicitly?

        What is weak reference

Guess you like

Origin blog.csdn.net/qq1090504117/article/details/111626008