SafeHandle.Dispose 方法

定义

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

重载

Dispose()

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

Dispose(Boolean)

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

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 ()

实现

注解

通过调用 CloseDispose 方法,可以释放资源。Calling 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.

Close使用完对象后,调用或 Dispose 方法 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 Dispose 释放对对象的最后一个引用之前,请始终调用或方法 SafeHandleAlways 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.

适用于

产品 已引入

Dispose(Boolean)

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

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

参数

disposing
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.

适用于

产品 已引入