我编写了一个非常简单的套接字,它只向网络中的设备发送 4 个字节,一切正常,但是每次创建新的套接字时,内存都会增加,并且在释放记忆。我写的代码如下:
Byte[] bytesSent = new byte[4];
bytesSent[0] = (byte)2;
bytesSent[1] = (byte)1;
bytesSent[2] = (byte)1;
bytesSent[3] = (byte)1;
Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sck.Connect(new IPEndPoint(IPAddress.Parse(ipAdd), 3152));
sck.Send(bytesSent, SocketFlags.None);
Thread.Sleep(10);
sck.Shutdown(SocketShutdown.Both);
sck.Close();
bytesSent = null;
在此先感谢您的帮助,