Frees a block of memory allocated by the unmanaged COM task memory allocator with Marshal.AllocCoTaskMem.
[Visual Basic] Public Shared Sub FreeCoTaskMem( _ ByVal ptr As IntPtr _ ) [C#] public static void FreeCoTaskMem( IntPtr ptr ); [C++] public: static void FreeCoTaskMem( IntPtr ptr ); [JScript] public static function FreeCoTaskMem( ptr : IntPtr );
- The address of the memory to be freed.
|ArgumentNullException||ptr is a null reference (Nothing in Visual Basic).|
You can use FreeCoTaskMem to free any memory allocated by AllocCoTaskMem, ReAllocCoTaskMem, or any equivalent unmanaged API. If the ptr parameter is a null reference (Nothing in Visual Basic), the method does nothing.
FreeCoTaskMem exposes the CoTaskMemFree COM API function, which frees all bytes so that you can no longer use the memory pointed to by the ptr parameter. For additional information about CoTaskMemFree, 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.