Do I have to store a TcpClient even though I only care about its stream?
Posted
by mafutrct
on Stack Overflow
See other posts from Stack Overflow
or by mafutrct
Published on 2010-03-08T11:45:26Z
Indexed on
2010/03/08
12:06 UTC
Read the original article
Hit count: 214
A new instance of a TcpClient connects to a remote host. Its NetworkStream is retrieved and stored. Do I have to store the TcpClient itself as well to make sure it is not garbage collected?
In case you're going to answer "You have to store it to be able to dispose it": In my specific case, the TcpClient is usually living for a long time (app lifetime), so disposing it is not really a must. However, I agree that, in general, it has to be stored just to be able to call Dispose.
© Stack Overflow or respective owner