Marshal.FreeHGlobal Method (IntPtr)
Frees memory previously allocated from the unmanaged memory of the process.
Assembly: mscorlib (in mscorlib.dll)
LocalFree function from Kernel32.DLL, which frees all bytes so that you can no longer use the memory pointed to by hglobal.exposes the
Passing an invalid handle value to ArgumentException.causes an
The following example demonstrates calling the Marshal class.method. This code example is part of a larger example provided for the
' Demonstrate how to call GlobalAlloc and ' GlobalFree using the Marshal class. Dim hglobal As IntPtr = Marshal.AllocHGlobal(100) Marshal.FreeHGlobal(hglobal)
The following example demonstrates how to convert the contents of a managed String class to unmanaged memory and then dispose of the unmanaged memory when done.
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Available since 8.1