Hello all-
I don't know if anyone has run into this sort of a problem before, but
I'm running out of ideas, so I thought I'd post this:
I have a multithreaded server application that accepts socket
connections from clients. The server is responsible for broadcasting
string-based messages to any connected clients as it receives these
messages (from a 3rd-party source).
The socket server aspect of the application implements the
asynchronous socket model. Using performance monitor, I noticed that
the application's memory usage would begin to start creeping up as a
function of messages broadcast to connected clients. I used the .NET
memory profiler from SciTech to try and pinpoint the problem. It
turned out that there were 3 types of objects not getting cleaned up
and causing my memory leak: OverlappedAsyncResult, Overlapped, and
byte[] (the raw data of the messages being broadcast).
So, then I ran the application in debug mode and reproduced the issue.
What I was able to discover thus far is that for some period of time,
the application will invoke the delegate I specify for BeginSend, as
it should. THEN, after that period of time, it appears that the
delegate is no longer invoked on subsequent calls to the BeginSend
method. This would seem to explain the memory leak, as my
corresponding calls to EndSend would no longer be invoked where,
presumably, cleanup of OverlappedAsyncResult, Overlapped, and byte[]
take place.
Anyway, I puzzled over this for a while and then discovered that after
I terminated my clients' socket connections, THEN the delegate
invocations that seemed to be missing beforehand actually came
through! This leads me to believe that somehow, asynchronous
invocations to the delegate specified in my call to BeginSend are
somehow queuing up.
Does this issue sound at all familiar to anyone out there? If so, any
insights would be greatly appreciated!!