System.Runtime.InteropServices.Marshal.FreeCoTaskMem Method

Frees a block of memory allocated by the unmanaged COM task memory allocator.

Syntax

public static void FreeCoTaskMem (IntPtr ptr)

Parameters

ptr
The address of the memory to be freed.

Remarks

You can use Marshal.FreeCoTaskMem(IntPtr) to free any memory allocated by Marshal.AllocCoTaskMem(int), Marshal.ReAllocCoTaskMem(IntPtr, int), or any equivalent unmanaged method. If the ptr parameter is null, the method does nothing.

Marshal.FreeCoTaskMem(IntPtr) exposes the COM tp://go.microsoft.com/fwlink/?LinkId=148638 function, which frees all bytes so that you can no longer use the memory that the ptr parameter points to.

In addition to Marshal.FreeCoTaskMem(IntPtr), the System.Runtime.InteropServices.Marshal class provides two other memory-deallocation methods: Marshal.DestroyStructure(IntPtr, Type) and Marshal.FreeHGlobal(IntPtr).

Requirements

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0