Muokkaa

Jaa


Marshal.DestroyStructure Method

Definition

Overloads

DestroyStructure(IntPtr, Type)
Obsolete.

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

DestroyStructure<T>(IntPtr)

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

DestroyStructure(IntPtr, Type)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.CoreCLR.cs

Caution

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

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

public:
 static void DestroyStructure(IntPtr ptr, Type ^ structuretype);
[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);
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.Security.SecurityCritical]
[System.Runtime.InteropServices.ComVisible(true)]
public static void DestroyStructure (IntPtr ptr, Type structuretype);
[<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>]
static member DestroyStructure : nativeint * Type -> unit
static member DestroyStructure : nativeint * Type -> unit
[<System.Security.SecurityCritical>]
static member DestroyStructure : nativeint * Type -> unit
[<System.Runtime.InteropServices.ComVisible(true)>]
static member DestroyStructure : nativeint * Type -> unit
[<System.Security.SecurityCritical>]
[<System.Runtime.InteropServices.ComVisible(true)>]
static member DestroyStructure : nativeint * Type -> unit
Public Shared Sub DestroyStructure (ptr As IntPtr, structuretype As Type)

Parameters

ptr
IntPtr

nativeint

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

Applies to

DestroyStructure<T>(IntPtr)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

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);
[<System.Security.SecurityCritical>]
static member DestroyStructure : nativeint -> unit
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

nativeint

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