GCHandle.Alloc Method (Object)
Assembly: mscorlib (in mscorlib.dll)
The object that uses the GCHandle.
Return ValueA new GCHandle that protects the object from garbage collection. This GCHandle must be released with Free when it is no longer needed.
An instance with nonprimitive (non-blittable) members cannot be pinned.
The following example shows an App class that creates a handle to a managed object using the GCHandle.Alloc method, which prevents the managed object from being collected. A call to the EnumWindows method passes a delegate and a managed object (both declared as managed types, but not shown), and casts the handle to an IntPtr. The unmanaged function passes the type back to the caller as a parameter of the callback function.
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.