Frees memory previously allocated from the unmanaged memory of the process with AllocHGlobal.
[Visual Basic] Public Shared Sub FreeHGlobal( _ ByVal hglobal As IntPtr _ ) [C#] public static void FreeHGlobal( IntPtr hglobal ); [C++] public: static void FreeHGlobal( IntPtr hglobal ); [JScript] public static function FreeHGlobal( hglobal : IntPtr );
- The handle returned by the original matching call to AllocHGlobal.
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 a null reference (Nothing in Visual Basic), the method does nothing.
FreeHGlobal exposes the GlobalFree 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 GlobalFree, see the MSDN Library.
Note This method uses SecurityAction.LinkDemand to prevent it from being called from untrusted code; only the immediate caller is required to have SecurityPermissionAttribute.UnmanagedCode permission. If your code can be called from partially trusted code, do not pass user input to Marshal class methods without validation. For important limitations on using the LinkDemand member, see Demand vs. LinkDemand.
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
- SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.