I have a main process that enqueue objects onto a Queue. When it is necessary, I queue the object. Otherwise, my main process does something else. I also have another thread that dequeues the object from the Queue, and process it.
When the Queue is empty, it takes a while to generate the Queue. I timed this. When I enqueue the second object, it takes shorter time than when I enqueue the first object.
When I dequeue the object, I have no problem. I can dequeue them one by one. However, after I dequeue the last object, the enqueueing of the next object (becomes the only object) takes a long time, comparable to when I enqueue the first object.
So I suspect that when the Queue is empty, the GC kicks in.
You talk about scope. Where is the boundary? If I spend most of my time in the main process, and once in a while call a function that enqueue the object, and the dequeueing is done in another thread, is the Queue is still in-scope? When I'm in the main process, is the Queue in-scope?
So the problem I'm having is the long time it takes to Queue an object that would become the first one in the Queue.