SafeHandle.Dispose SafeHandle.Dispose SafeHandle.Dispose SafeHandle.Dispose Method

定义

释放 SafeHandle 类使用的资源。Releases the resources used by the SafeHandle class.

重载

Dispose() Dispose() Dispose() Dispose()

释放 SafeHandle 类使用的所有资源。Releases all resources used by the SafeHandle class.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放 SafeHandle 类所使用的非托管资源,并指定是否执行常规释放 (Dispose) 操作。Releases the unmanaged resources used by the SafeHandle class specifying whether to perform a normal dispose operation.

Dispose() Dispose() Dispose() Dispose()

释放 SafeHandle 类使用的所有资源。Releases all resources used by the SafeHandle class.

public:
 virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()

实现

注解

通过调用Dispose或方法,可以释放资源。 CloseCalling the Close or Dispose method allows the resources to be freed. 如果其他线程使用安全句柄的同一个实例,这可能不会立即发生,但一旦不再出现,就会发生这种情况。This might not happen immediately if other threads are using the same instance of the safe handle, but will happen as soon as that is no longer the case. 尽管使用SafeHandle的大多数类不需要提供终结器,但有时需要执行此操作(例如,刷新文件缓冲区或将一些数据写回内存中)。Although most classes using SafeHandle do not need to provide a finalizer, this is sometimes necessary (for example, to flush out file buffers or to write some data back into memory). 在这种情况下,它们可以提供保证在SafeHandle关键终结器运行之前运行的终结器。In this case, they can provide a finalizer that is guaranteed to run before the SafeHandle critical finalizer runs.

使用完对象后,调用Dispose 或方法。Close SafeHandleCall the Close or Dispose method when you are finished using the SafeHandle object. Close 方法SafeHandle使对象处于不可用状态。The Close method leaves the SafeHandle object in an unusable state.

备注

在释放对Close对象DisposeSafeHandle最后一个引用之前,请始终调用或方法。Always call the Close or Dispose method before you release your last reference to the SafeHandle object. 否则,在垃圾回收器调用 SafeHandle 对象的 Finalize 方法之前,该对象正在使用的资源不会被释放。Otherwise, the resources it is using will not be freed until the garbage collector calls the SafeHandle object's Finalize method.

安全性

SecurityPermission
用于调用非托管代码的权限。for permission to call unmanaged code. 安全操作: LinkDemandSecurity action: LinkDemand. 关联的枚举:UnmanagedCodeAssociated enumeration: UnmanagedCode

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放 SafeHandle 类所使用的非托管资源,并指定是否执行常规释放 (Dispose) 操作。Releases the unmanaged resources used by the SafeHandle class specifying whether to perform a normal dispose operation.

protected:
 virtual void Dispose(bool disposing);
[System.Security.SecurityCritical]
protected virtual void Dispose (bool disposing);
abstract member Dispose : bool -> unit
override this.Dispose : bool -> unit
Protected Overridable Sub Dispose (disposing As Boolean)

参数

disposing
Boolean Boolean Boolean Boolean

如进行常规释放操作,则为 true;如终结句柄,则为 falsetrue for a normal dispose operation; false to finalize the handle.

注解

不应显式调用Dispose方法disposing ,参数设置为falseYou should never explicitly call the Dispose method with the disposing parameter set to false.

安全性

SecurityPermission
用于调用非托管代码的权限。for permission to call unmanaged code. 安全操作: LinkDemandSecurity action: LinkDemand. 关联的枚举:UnmanagedCodeAssociated enumeration: UnmanagedCode

适用于