Should I store TcpClient, although I only care about its stream?

A new instance of TcpClient connects to the remote host. Its NetworkStream is retrieved and saved. Should I also store TcpClient itself to make sure this is not garbage collection?

In case you answer "You must save it in order to be able to dispose of it": In my particular case, TcpClient usually lives for a long time (application lifetime), so getting rid of it is not necessary. However, I agree that in general it must be saved in order to be able to call Dispose.

+3
source share
2 answers

, . , - , , .

, , TcpClient , , TcpClient . , TcpClient. ( , , , .)

+2

, , NetworkStream . TcpClient, .

+1

Source: https://habr.com/ru/post/1735909/


All Articles