Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:00:21+00:00 2026-06-15T05:00:21+00:00

I am basically looking for a container of image collections acquired from camera in

  • 0

I am basically looking for a container of image collections acquired from camera in a thread. Since ConcurrentQueue is thread-safe, I wanted to use it. But while debugging my code, I found this article saying

If the elements are small, you’ll probably never notice this. If,
however, the elements hold on to large resources (e.g. each element is
a huge image bitmap), it’s possible you could see the impact of this
(one workaround is to queue a wrapper object, e.g. have a
ConcurrentQueue<StrongBox<T>> rather than a ConcurrentQueue<T>, and
null out the wrapper’s reference to the T value after the wrapper has
been dequeued).

As far as I can see, StrongBox is a kind of wrapper for original value. Does that mean I have to store another collection of the images?

So I am looking for an usage or an example of ConcurrentQueue<StrongBox<T>>. Only thing I found from google is this code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:00:23+00:00Added an answer on June 15, 2026 at 5:00 am

    The reminder of the dangers of premature optimization are in the comments, so I will address the semantics of what’s going on here.

    Like the article points out, the ConcurrentQueue can hold on to references of some things that have already gone through it. I learned it as ‘a few dozen’ and the article says it is no more than 31, which seems to gel pretty nicely. If the queue is tracking big objects, like your 2000×2000 Bitmaps, that can theoretically become a problem. It depends on what the rest of your program is doing, of course.

    Wrapping it in a StrongBox<T> helps because the only thing StrongBox does is hold onto a reference to something else. Therefore, a StrongBox has a very tiny footprint, and whatever it holds will go out of scope and (theoretically) get GC’d quicker.

    Since StrongBox has all the content of diet soda, you’re kind of overthinking its usage. You literally just load up the Value field with some T and then reference it later. It looks a little like this:

    var boxedBitmap = new StrongBox<Bitmap>(new Bitmap(1,1));
    var bitmap = boxedBitmap.Value;
    

    Or alternatively:

    var boxedBitmap = new StrongBox<Bitmap>();
    boxedBitmap.Value = new Bitmap(1,1);
    var bitmap = boxedBitmap.Value;
    

    Seriously, the implementation of this class if you pop it open in Reflector is like 5 lines.

    This being the case, your usage of ConcurrentQueue<T> is not really any different from the usage of ConcurrentQueue<StrongBox<T>>. You’ll simply tack on .Value before you send the resource to its destination thread. This did help a company I worked for reduce the memory imprint of a massive multithreaded analysis service by quite a bit by simply passing around a reference to a deterministic tool instead of passing the entire tool around, but your mileage may vary – I am not clear on what ramifications it would have if you were passing something to be mutated and then used by something else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically just looking to see if you can capture an image from the webcam
Basically I'm looking to convert a Timestamp field from the: 2012-03-14 23:14:58 format to
Basically what I am looking to do is populate a dropdown box from the
Basically, I am looking for a way to center a container that is 1600px
My team's current project involves re-writing retrieval libraries in JavaScript. We are basically looking
Basically I am looking for a win32 method to invoke in C# to set
Good day, Basically i am looking for a way to retrieve and save a
Basically I'd be looking to implement a method like this. IQueryAble GetQuery<T>(Entities db) or
Basically, I'm looking for something that will allow me to replicate the following Perl
Basically, I am using Wireshark looking at captures that have been created previously. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.