Folks, lots of things in the FCL implement IDisposable and forgetting to
dispose of most them won't normally cause any damage. The garbage collector
runs at unpredictable intervals and finds things like forgotten streams and
DB connections and cleans things up long before you'd hit things like
handle limits.

However, I had a svcutil generated proxy class with two Dispose methods and
I had the cleanup code in the wrong one. This went unnoticed for months
until I looked into why we would get occasional random pauses or hang-ups
in the service during heavy bursts of use. Stepping way down into the code
I found the wrong Dispose, and fixing this cured the problem.

It turns out that WCF services have a default limit of 10 (or 16?)
connections after which new ones block. Because the clients weren't being
disposed, they would hang around for a random interval until the GC took
them. If their instance count randomly reached the WCF limit then the
service would pause or stall. So the problem was caused by an unfortunate
combination of the coding error and the environment. Beware ... Dispose
carefully and often!

*Greg K*

Reply via email to