.NET Framework - Possible memory-leaky classes?

Posted by Robert Fraser on Stack Overflow See other posts from Stack Overflow or by Robert Fraser
Published on 2010-04-20T19:51:14Z Indexed on 2010/04/20 19:53 UTC
Read the original article Hit count: 277

Just the other day I was investigating a memory leak that was ballooning the app from ~50MB to ~130MB in under two minutes. Turns out that the problem was with the ConcurrentQueue class. Internally, the class stores a linked list of arrays. When an item is dequeued from the ConcurrentQueue, the index in the array is bumped, but the item remains in the array (i.e. it's not set to null). The entire array node is dropped after enough enqueues/dequeues, so it's not technically a leak, but if storing only a few large objects in the ConcurrentQueue, this can get out of hand fast. The documentation makes no note of this danger.

I was wondering what other potential memory pitfalls are in the Base Class Library? I know about the Substring one (that is, if you call substring and just hold onto the result, the whole string will still be in memory). Any others you've encountered?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET