NetworkStream.IDisposable.Dispose 方法

定义

释放由 NetworkStream 使用的所有资源。Releases all resources used by the NetworkStream.

此 API 支持产品基础结构,不能在代码中直接使用。

 virtual void System.IDisposable.Dispose() = IDisposable::Dispose;
void IDisposable.Dispose ();
override this.System.IDisposable.Dispose : unit -> unit
Sub Dispose () Implements IDisposable.Dispose

实现

注解

在完成使用 Dispose 后,应调用 NetworkStreamCall Dispose when you are finished using the NetworkStream. Dispose 方法使 NetworkStream 处于不可用状态。The Dispose method leaves the NetworkStream in an unusable state. 调用后 Dispose ,必须释放对的所有引用, NetworkStream 以便垃圾回收器能够回收占用的内存 NetworkStreamAfter calling Dispose, you must release all references to the NetworkStream so the garbage collector can reclaim the memory that the NetworkStream was occupying. 有关使用 Dispose 方法的详细信息,请参阅 清理非托管资源实现 Dispose 方法For more information about using the Dispose method, see Cleaning Up Unmanaged Resources and Implementing a Dispose Method.

备注

每次释放对 Dispose 的最后一个引用前,均应调用 NetworkStreamAlways call Dispose before you release your last reference to the NetworkStream. 否则,在垃圾回收器调用 NetworkStream 对象的 Finalize 方法之前,不会释放它所使用的资源。Otherwise, the resources it is using are not freed until the garbage collector calls the NetworkStream object's Finalize method.

适用于