Marshal.DestroyStructure Method

Definition

Overloads

DestroyStructure(IntPtr, Type)

Frees all substructures that the specified unmanaged memory block points to.

DestroyStructure<T>(IntPtr)

[Supported in the .NET Framework 4.5.1 and later versions]

Frees all substructures of a specified type that the specified unmanaged memory block points to.

DestroyStructure(IntPtr, Type)

Warning

This API is now obsolete.

Frees all substructures that the specified unmanaged memory block points to.

public:
 static void DestroyStructure(IntPtr ptr, Type ^ structuretype);
[System.Security.SecurityCritical]
[System.Obsolete("DestroyStructure(IntPtr, Type) may be unavailable in future releases. Instead, use DestroyStructure<T>(IntPtr). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296520")]
public static void DestroyStructure (IntPtr ptr, Type structuretype);
public static void DestroyStructure (IntPtr ptr, Type structuretype);
[System.Security.SecurityCritical]
public static void DestroyStructure (IntPtr ptr, Type structuretype);
[System.Runtime.InteropServices.ComVisible(true)]
public static void DestroyStructure (IntPtr ptr, Type structuretype);
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public static void DestroyStructure (IntPtr ptr, Type structuretype);
static member DestroyStructure : nativeint * Type -> unit
Public Shared Sub DestroyStructure (ptr As IntPtr, structuretype As Type)

Parameters

ptr
IntPtr

A pointer to an unmanaged block of memory.

structuretype
Type

Type of a formatted class. This provides the layout information necessary to delete the buffer in the ptr parameter.

Attributes

Exceptions

structureType has an automatic layout. Use sequential or explicit instead.

Remarks

You can use this method to free reference-type fields, such as strings, of an unmanaged structure. Unlike its fields, a structure can be a value type or a reference type. Value-type structures that contain value-type fields (all blittable) have no references whose memory must be freed. The Marshal.StructureToPtr method uses this method to prevent memory leaks when reusing memory occupied by a structure.

DestroyStructure calls the COM SysFreeString function, which, in turn, frees an allocated string.

In addition to DestroyStructure, the Marshal class provides two other memory-deallocation methods: FreeCoTaskMem and FreeHGlobal.

See also

DestroyStructure<T>(IntPtr)

[Supported in the .NET Framework 4.5.1 and later versions]

Frees all substructures of a specified type that the specified unmanaged memory block points to.

public:
generic <typename T>
 static void DestroyStructure(IntPtr ptr);
[System.Security.SecurityCritical]
public static void DestroyStructure<T> (IntPtr ptr);
public static void DestroyStructure<T> (IntPtr ptr);
static member DestroyStructure : nativeint -> unit
Public Shared Sub DestroyStructure(Of T) (ptr As IntPtr)

Type Parameters

T

The type of the formatted structure. This provides the layout information necessary to delete the buffer in the ptr parameter.

Parameters

ptr
IntPtr

A pointer to an unmanaged block of memory.

Attributes

Exceptions

T has an automatic layout. Use sequential or explicit instead.

Remarks

You can use this method to free reference type fields, such as strings, of an unmanaged structure. Unlike its fields, a structure can be a value type or a reference type. Value type structures that contain value type fields (all blittable) have no references whose memory must be freed. The Marshal.StructureToPtr method uses this method to prevent memory leaks when reusing memory occupied by a structure.

DestroyStructure calls the COM SysFreeString function, which, in turn, frees an allocated string.

Applies to