Results 1 to 3 of 3

Thread: TcpClient.Close question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    USA
    Posts
    150

    TcpClient.Close question

    well its a garbage collection question as well.

    After TcpClient.Close() I take it the garbage collector does its job and removes it from memory etc.

    or am I wrong?

    (Chris128 put your handdown and let somebody else answer )

  2. #2
    Addicted Member Rockhopper's Avatar
    Join Date
    Aug 2003
    Location
    Cape Town, South Africa
    Posts
    199

    Re: TcpClient.Close question

    I would assume it would dispose the TCPClient (or mark it for disposal at least).

    What I don't know is that if you Close the TCPClient, and leave the NetworkStream open, whether the reference to the NetworkStream will keep the TCPClient in memory and prevent the Garbage Collector from removing the TCPClient. If you make sure that you close the network stream before you close the TCPClient, I can't see why it wouldn't be collected.

    http://msdn.microsoft.com/en-us/libr...se(VS.80).aspx

    "The Close method marks the instance as disposed but does not close the TCP connection. Calling this method does not release the NetworkStream that is used to send and receive data. You must call the Close method to close the stream and the TCP connection."

    If you use CLRProfiler, you should be able to test whether the TCPClient has been disposed properly.
    If the facts don't fit the theory, change the facts. --Albert Einstein

  3. #3
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: TcpClient.Close question

    haha I could not have answered this one anyway because I didnt know this:
    Calling this method does not release the NetworkStream that is used to send and receive data
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width