Alex Rivera | Logout

Should I manually dispose the socket after closing it?

Asked 2010-08-30T14:55:07.290
39

Should I still call Dispose() on my socket after closing it?

For example:

mySocket.Shutdown(SocketShutdown.Both);
mySocket.Close();
mySocket.Dispose(); // Redundant?

I was wondering because the MSDN documentation says the following:

Closes the Socket connection and releases all associated resources.

Edit
Report

1 Answer

0

You are right. The documentation is not clear since in the dispose method it is written that you should call Dispose() to clean the socket unmanaged resources, but on the other hand Close should do the same. I guess that Close calls Dispose or the contrary. The same behavior is supported by files so it is an educated guess.

answered 2010-08-30T15:02:14.623

Your Answer