See Also: GCHandle Members
The System.Runtime.InteropServices.GCHandle structure is used with the System.Runtime.InteropServices.GCHandleType enumeration to create a handle corresponding to any managed object. This handle can be one of four types: Weak, WeakTrackResurrection, Normal, or Pinned. When the handle has been allocated, you can use it to prevent the managed object from being collected by the garbage collector when an unmanaged client holds the only reference. Without such a handle, the object can be collected by the garbage collector before completing its work on behalf of the unmanaged client.
You can also use System.Runtime.InteropServices.GCHandle to create a pinned object that returns a memory address to prevent the garbage collector from moving the object in memory.
When the handle goes out of scope you must explicitly release it by calling the GCHandle.Free method; otherwise, memory leaks may occur. When you free a pinned handle, the associated object will be unpinned and will become eligible for garbage collection, if there are no other references to it.