System.IO.Stream.Dispose Method

Releases the unmanaged resources used by the System.IO.Stream and optionally releases the managed resources.

Syntax

protected virtual void Dispose (bool disposing)

Parameters

disposing
true to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks

You should release all resources by specifying true for disposing. When disposing is true, the stream can also ensure data is flushed to the underlying buffer, and access other finalizable objects. This may not be possible when called from a finalizer due a lack of ordering among finalizers.

If your stream is using an operating system handle to communicate with its source, consider using a subclass of System.Runtime.InteropServices.SafeHandle for this purpose.

This method is called by the public System.ComponentModel.Component.Dispose method and the object.Finalize method. System.ComponentModel.Component.Dispose invokes the protected Stream.Dispose(bool) method with the disposing parameter set to true. object.Finalize invokes Stream.Dispose(bool) with disposing set to false.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0