So this is a .NET CF 3.5 app, running on CE7. The problem is also visible in CE5.
We use HttpWebRequests to query a server. When online, all seems well.
When server is unavailable, we observe what appears to be a resource leak.
Using the CF remote performance monitor, we can see tens of thousands of weak references pile up (eventually), never going away. Occupying loads of memory. The heap grows linearly. See screenshots.
They're all marked as roots, and finalizer. I get the feeling the finalizer for the webrequest is not working properly somehow, but not quite sure how to interpret all this.
When the request is complete (or an exception happens) we dispose of the IDisposables on the request (the request stream and response stream).
Could you explain what is going on here please? Why are all those weakreferences accumulating and not getting garbage collected? Any insight appreciated.
Thanks.
EDIT:
It's probably also worth mentioning, that in the debugger, we occasionally see this ObjectDisposedException exception, which is uncaught, and brings down the app (since its on Threadpool thread). Only occasionally. May/may not be related to above leak. We've tried every variant of using/disposing/not disposing/closing of the streams we can, and every bit of found advice on this,to no avail.
at System.Threading.Timer.throwIfDisposed()
at System.Threading.Timer.Change(UInt32 dueTime, UInt32 period)
at System.Threading.Timer.Change(Int32 dueTime, Int32 period)
at System.Net.HttpWebRequest.startReadWriteTimer()
at System.Net.HttpWebRequest.ConnectionClient.Read(Byte[] data, Int32 offset, Int32 length)
at System.Net.HttpReadStream.NetworkRead(Byte[] data, Int32 offset, Int32 length)
at System.Net.ContentLengthReadStream.doRead(Byte[] data, Int32 offset, Int32 length)
at System.Net.HttpReadStream.ReadToDrain(Byte[] buffer, Int32 offset, Int32 length)
at System.Net.HttpReadStream.doClose()
at System.Net.ContentLengthReadStream.doClose()
at System.Net.HttpReadStream.Finalize()