title: How to release reference from the ConcurentQueue for the item dequeued from the concurrent queue with TryDequeue
body: <p>I am using ConcurrentQueue (C#, ASP.NET Core) for holding tasks for the upload of the big files. I have a very big memory consumption even after items are dequeued from the concurrent queue. Items are not cleared from the memory.</p>
  
  <p>I understand behavior of the ConcurrentQueue in ASP.NET Core which is in short: every group of the 32 items in a concurrent queue are saved in a separate segment. References are released for dequeued items only after all items from the particular segment are dequeued, and not after TryDequeue() method is called for a single item. This is a problem in my case because I can have very large amount in the memory if in the worst case 32 items are not cleaned, which are potentially very big zip files. I even don't expect to have more than 32 items in the queue in the same time.</p>
  
  <p>Even I extract files and send them separately, every file/image inside can be also big by itself. The only thing which is good enough for me is to release reference for every dequeued item, without further postponing. Is it possible and how?</p>
  
  <p>I tried to use StrongBox, recommended in some articles:</p>
  
  <pre><code>ConcurrentQueue&lt;StrongBox&lt;Func&lt;CancellationToken, Task&gt;&gt;&gt; 
  workItems = new ConcurrentQueue&lt;StrongBox&lt;Func&lt;CancellationToken, Task&gt;&gt;&gt;();
  
  // Enqueuing:
  this.workItems.Enqueue(new StrongBox&lt;Func&lt;CancellationToken, Task&gt;&gt;(workItem));
  
  // Dequeuing:
  workItems.TryDequeue(out var workItem);
  return workItem.Value;
  </code></pre>
  
  <p>This was not useful in my case. Memory was not freed. I don't know it my problem is related to the fact that I am sending reference to the function to the queue and it is somehow held in a memory. One of the parameters of this function is a concrete file for upload. Others are just strings.</p>
  
  <p>To conclude, I would like to take care of the memory release for the item, after or during TryDequeue() method is called. Is it possible and how?</p>