Marshal.DestroyStructure 方法

定义

重载

DestroyStructure(IntPtr, Type)
已过时.

释放指定的非托管内存块所指向的所有子结构。

DestroyStructure<T>(IntPtr)

释放指定的非托管内存块所指向的所有指定类型的子结构。

DestroyStructure(IntPtr, Type)

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

注意

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);
[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)

参数

ptr
IntPtr

nativeint

指向非托管内存块的指针。

structuretype
Type

格式化类的类型。 该类型提供删除 ptr 参数指向的缓冲区时必需的布局信息。

属性

例外

structureType 具有自动布局。 但请该用连续或显式布局。

注解

可以使用此方法释放非托管结构的引用类型字段,例如字符串。 与其字段不同,结构可以是值类型或引用类型。 包含值类型字段的值类型结构 (所有 blittable) 没有必须释放其内存的引用。 方法 Marshal.StructureToPtr 使用此方法防止在重用结构占用的内存时发生内存泄漏。

DestroyStructure 调用 COM SysFreeString 函数,后者又释放分配的字符串。

除了 DestroyStructure之外, Marshal 类还提供另外两种内存解除分配方法: FreeCoTaskMemFreeHGlobal

另请参阅

适用于

DestroyStructure<T>(IntPtr)

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

释放指定的非托管内存块所指向的所有指定类型的子结构。

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)

类型参数

T

格式化结构的类型。 该类型提供删除 ptr 参数指向的缓冲区时必需的布局信息。

参数

ptr
IntPtr

nativeint

指向非托管内存块的指针。

属性

例外

T 具有自动布局。 但请该用连续或显式布局。

注解

可以使用此方法释放非托管结构的引用类型字段,如字符串。 与其字段不同,结构可以是值类型或引用类型。 包含值类型字段 (所有 blittable) 的值类型结构没有必须释放其内存的引用。 方法 Marshal.StructureToPtr 使用此方法防止在重用结构占用的内存时发生内存泄漏。

DestroyStructure 调用 COM SysFreeString 函数,后者又释放分配的字符串。

适用于