You can use FreeHGlobal to free any memory from the global heap allocated by AllocHGlobal, ReAllocHGlobal, or any equivalent unmanaged API method. If the hglobal parameter is IntPtr.Zero, the method does nothing.
FreeHGlobal exposes the LocalFree function from Kernel32.DLL, which frees all bytes so that you can no longer use the memory pointed to by hglobal. For additional information about LocalFree, see the MSDN Library.
In addition to FreeHGlobal, the Marshal class provides two other memory-deallocation API methods: DestroyStructure and FreeCoTaskMem.
Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition Platform Note:
Passing an invalid handle value to FreeHGlobal causes an ArgumentException.