Memory Leak

Jan 5, 2009 at 11:01 AM
I am using your code ragorously and I appreciate your effort. This has helped me quite a lot. But there seems to be an issue. HttpClientContextImp object is initiated with every new connection request but it is never released. (I have added a destructor to the class and observed that this is never invoked) This is the reason my exe keeps growing. Have you observed this. Kindly provide me the feedback on this.

Thanks
Mubashir
Coordinator
Jan 5, 2009 at 12:43 PM
have you tried to force garbage collection?

Jan 6, 2009 at 5:15 AM
Yes I have tried to force the garbage collector. And observed that the HttpClientContextImp is never collected. This seems like a big issue. Has anyone ever reported this before. I guess there is some cyclic reference that .NET is unable to resolve. Could you please provide a fix at your earliest. I would be very gratefull.

Thanks
Mubashir 
Coordinator
Jan 6, 2009 at 6:57 PM
I've rewritten some stuff that I was not satisfied with. One can now use an own http parser and/or ihttpclientcontext. The default implementation are now reusing HttpClientContextImp, i.e. it's added to a pool when a client disconnects.

Jan 27, 2009 at 1:34 PM
Hi,

I noticed that the pooling seems to not work properly as HttpClientContextImp is never started and returned when it is returned from the queue (pool). See the code below taken from the HttpContextFactory class:

protected HttpClientContextImp CreateContext(bool isSecured, IPEndPoint endPoint, Stream stream)
{
lock (_contextQueue)
{
if (_contextQueue.Count > 0)
{
HttpClientContextImp context = _contextQueue.Dequeue();
context.Stream = stream;
context.IsSecured = isSecured;
context.RemotePort = endPoint.Port.ToString();
context.RemoteAddress = endPoint.Address.ToString();
}
}


var imp = new HttpClientContextImp(isSecured, endPoint, stream, _factory, _bufferSize);
imp.Disconnected += OnFreeContext;
imp.RequestReceived += OnRequestReceived;
imp.Start();
return imp;
}

It should probably look like the following code with two lines added:

if (_contextQueue.Count > 0)
{
HttpClientContextImp context = _contextQueue.Dequeue();
context.Stream = stream;
context.IsSecured = isSecured;
context.RemotePort = endPoint.Port.ToString();
context.RemoteAddress = endPoint.Address.ToString();
context.Start();
return imp;
}
Coordinator
Jan 27, 2009 at 1:47 PM
You are correct. Have commited a fix. thanks.