I have a simple .NET 3.5sp1 window application (in C #) that acts as a UDP server. It listens on a port, receives data from a closing point, and then reconstructed to achieve a second endpoint (i.e., a relay for a live broadcast data stream). After the connection is about 20 minutes, I am experiencing this, it starts to deteriorate. Besides, I think it is messing up 50-100K memory per second, which is released after GC not happening. I have to close the app and have to restart it. Not good I have narrowed the problem to the code given below, which restores the other side:
var sendBuffer = new byte [readCount]; Array.Copy (redData, SendBuffer, Reddit); SocketAsyncEventArgs args = New SocketSync EventArgent (); Args.RemoteEndPoint = PAP; Args.Setbuffer (sendBuffer, 0, sendBuffer.Length); SwitchWindow.LineSocket.SendToAsync (args); Update:
I institute a state object (only done once) when the socket is started. State object has a property called "buffer", which is a byte array. I get the data async from the socket in this way:
Start Private Zero ResaveData (Refer Mestet State) {var ipeSender = New IPPpoint (IPadation. Any, 0); Var epSender = (Endpoint) ipeSender; State.workSocket = LineSocket; state. EP = Episcencer; State.workSocket.BeginReceiveFrom (state.buffer, 0, message status. Buffer size, socketflags.No, ref appendender, new async callback (receipt data b), state); }
And, on my callback (receiverdcb), I am retrieving the async object, and then processing the byte buffer to another function, which in turn The code calls the code above for the code. On the other hand, the revision (state buffer is read).
UPDATE # 2:
After my stomach, I changed the code by sending the following, getting rid of SocketAsyncEventArgs and SendToAsync:
var sendBuffer = new byte [readCount]; Array.Copy (redData, SendBuffer, Reddit); SwitchWindow.LineSocket.BeginSendTo (sendBuffer, 0, sendBuffer.Length, SocketFlags.None, PAP, New AsyncCallback (echoCB), blank);
And, of course, I have added an "eCossibie" callback that does nothing except calling the endend memory leak is now gone! I suspect that there was something like this with the creation of so many socket adventure events in it, and hanging the funcons functions, one for each packet (33 packets per second, which can be added fast). I once again used the Socket Asynchronous Errgs Viewed in MSDN documentation, and I found that the server was provided on the "example" code, they used a pool of SocketAsyncEventArgs objects. I do not think this is actually designed to work the way I was using it. I think the whole point is not to instantiate these buffers, etc. for each call, so they have to use them again and allow the server to perform better.
You probably are not calling SocketAsyncEventArgs. Dispose ()
Comments
Post a Comment