Say I have a Stream produced via TcpClient.GetStream(). If I stream.Dispose(), is it necessary to dispose of the TcpClient that created the Stream?
Say I have a Stream produced via TcpClient.GetStream() . If I stream.Dispose() , is
Share
Looking at the implementations of
TcpClient.GetStreamandTcpClient.Disposein ILSpy, I agree that you should not have a resource leak if you callDispose()on the stream but not on the client.However, I am not convinced it is a good idea anyway.
I’d ask why you want to avoid calling
Dispose()on the instance ofTcpClient. The contract implied by the fact thatTcpClientimplementsIDisposableis thatDispose()should be called when an instance is no longer required.If you break this contract:
TcpClientchanges in future versions?