Visual studio feeds

All Visual Studio blogs in one place


Enter your email address:

Delivered by FeedBurner

Increase your website traffic with



Anti-spam: How many eyes has a typical person?

Follow us on FB


Real-life story: Blocking Collection

AddThis Social Bookmark Button
Real-life story: Blocking Collection this post will discuss a real-life story which uncover none trivial (yet logical) behavior which related to Parallel.ForEach and BlockingCollection. I will explain why it happens and what how can we handle it right. it all start when Guy Eden from ITG has found that the following code seem to leak memory:
Code Snippet
private static void Main() {     var bc = new BlockingCollection();     Task.Factory.StartNew(() =>         Parallel.ForEach(bc.GetConsumingEnumerable(), i => { }));     Console.ReadKey(); }
it was leaking even those the
blocking collection were empty (nothing was adding item to the collection). while monitoring this code we can see a steep memory curve constantly raising up to the sky.   I found it very surprising  because it seem quit reasonable scenario and BlockingCollection is a prime member of the new TPL concurrent collection family. so I have decided to ask Stephen Toub about this behavior and as always Stephen has enlighten me about what is really happening in this scenario. the following is a snippet from Stephen's response: "The Parallel.ForEach uses the...(Read whole news on source site)

Home : Blog List : [Export] Bnaya Eshet : Real-life story: Blocking Collection