System.Runtime.InteropServices.Marshal.FreeCoTaskMem Method

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


public static void FreeCoTaskMem (IntPtr ptr)


The address of the memory to be freed.


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:// 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).


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