MemoryStream.Dispose(Boolean) 方法


释放 MemoryStream 类使用的非托管资源,并可以选择释放托管资源。Releases the unmanaged resources used by the MemoryStream class and optionally releases the managed resources.

 override void Dispose(bool disposing);
protected override void Dispose (bool disposing);
override this.Dispose : bool -> unit
Protected Overrides Sub Dispose (disposing As Boolean)



若要释放托管资源和非托管资源,则为 true;若仅释放非托管资源,则为 falsetrue to release both managed and unmanaged resources; false to release only unmanaged resources.


此方法由 public Dispose 方法和 Finalize 方法调用。This method is called by the public Dispose method and the Finalize method. Dispose 调用受保护的 Dispose 方法,并将 disposing 参数设置为 trueDispose invokes the protected Dispose method with the disposing parameter set to true. Finalize 调用 disposing 设置为 falseDisposeFinalize invokes Dispose with disposing set to false.

disposing 参数为 true 时,此方法释放该 MemoryStream 引用的、由任何托管对象持有的全部资源。When the disposing parameter is true, this method releases all resources held by any managed objects that this MemoryStream references. 此方法调用每个引用对象的 Dispose 方法。This method invokes the Dispose method of each referenced object.


Dispose() 可以由其他对象多次调用。 Dispose() can be called multiple times by other objects. Dispose(Boolean) 重写时,请注意不要引用先前在调用 Dispose()之前已释放的对象。When overriding Dispose(Boolean) be careful not to reference objects that have been previously disposed of in an earlier call to Dispose(). 有关如何实现 Dispose(Boolean)的详细信息,请参阅[实现 Dispose 方法](~/docs/standard/garbage-collection/。For more information about how to implement Dispose(Boolean), see [Implementing a Dispose Method](~/docs/standard/garbage-collection/ 有关 Dispose()Finalize()的详细信息,请参阅[清理非托管资源](~/docs/standard/garbage-collection/。For more information about Dispose() and Finalize(), see [Cleaning Up Unmanaged Resources](~/docs/standard/garbage-collection/