Question

The MSDN remarks at http://msdn.microsoft.com/en-us/library/dd267312.aspx state that...

"The default collection type for BlockingCollection is ConcurrentQueue"

Does this mean that while I am running "GetConsumingEnumerable()" on the collection, the item pulled is being dequeued from the queue and after use will be marked for GC?

In other words... In the following snippet,

foreach (var item in collection.GetConsumingEnumerable())
        {
            //do something with item
        }

what happens to item after the loop iteration?

Était-ce utile?

La solution

The items will be removed from the collection, and if no other references to them exist they will be eligible for collection.

From the documentation of GetConsumingEnumerable:

Return Value
Type: System.Collections.Generic.IEnumerable<T>
An IEnumerable<T> that removes and returns items from the collection.

(my emphasis)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top