Marshal.DestroyStructure Marshal.DestroyStructure Marshal.DestroyStructure Marshal.DestroyStructure Method

Definition

Overloads

DestroyStructure(IntPtr, Type) DestroyStructure(IntPtr, Type) DestroyStructure(IntPtr, Type) DestroyStructure(IntPtr, Type)

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

DestroyStructure<T>(IntPtr) DestroyStructure<T>(IntPtr) DestroyStructure<T>(IntPtr) 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) DestroyStructure(IntPtr, Type) DestroyStructure(IntPtr, Type) 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.Runtime.InteropServices.ComVisible(true)]
[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")]
[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 IntPtr IntPtr IntPtr

A pointer to an unmanaged block of memory.

structuretype
Type Type Type Type

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

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.

Security

SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

See Also

DestroyStructure<T>(IntPtr) DestroyStructure<T>(IntPtr) DestroyStructure<T>(IntPtr) 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);
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 IntPtr IntPtr IntPtr

A pointer to an unmanaged block of memory.

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.

Security

SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Applies to