BlockingCollection holds references to its contents even after they have been removed - by Scripticus

Status : 

  Duplicate<br /><br />
		This item appears to be a duplicate of another existing Connect or internal item.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 626251 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 12/1/2010 7:59:12 AM
Access Restriction Public


The  BlockingCollection object (and possibly others) has some internal structures that hold referneces to its contents. There must be some sort of cycling pool of these object because after all the contents have been removed, something in there is still holding references to the noe removed objects. This prevents them from being garbage collected. In my case, it was 50MB BitmapSource object and after adding and removing 0 or so, my app runs out of memory.
Sign in to post a comment.
Posted by Microsoft on 12/14/2010 at 11:53 AM
Hi Moorster2-

Thanks for taking the time to report this issue! The problem was in ConcurrentQueue, which is used by default in BlockingCollection (unless you specify an alternate IProducerConsumerCollection when you construct the BlockingCollection). The bug was that ConcurrentQueue would maintain references to up to the last 32 elements in the queue, even if those elements were removed, and thus that behavior translates to BlockingCollection as well. The problem has already been fixed for a future release.

Stephen Toub
Parallel Computing Platform
Posted by Microsoft on 12/5/2010 at 9:29 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Scripticus on 12/2/2010 at 7:21 AM
I just uploaded a sample project that demonstrates the problem and the workaround. It's in the zip file named

Posted by Microsoft on 12/1/2010 at 9:53 PM
Thanks for reporting this issue. Please give us a demo project to demonstrate this issue so that we can conduct further research.

Thanks again for your efforts and we look forward to hearing from you.

Microsoft Visual Studio Connect Support Team
Posted by Microsoft on 12/1/2010 at 5:53 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(