my program contains a concurrent_queue. A producer thread is pushing event class-pointers to this queue, my consumer thread pops the event pointers, processes them and deletes the object behind.
Deleting the objects is working well, since the destructor is being called. However I have the problem that the concurrent_queue doesn't seem to free the memory it used again. This is a problem for me since I'm adding millions of pointers to the queue which consumes almost 2 GB of memory. I definitely need to free this memory again otherwise my application can't continue.
I looked through the forum and found that this problem has been discussed before however I couldn't find any solution to that. I'm really sorry if a solution has been proposed and I just didn't find it. I would be really happy if someone could give me some advice on how to deal with this problem.
Hi, I will test these things myself with the producer-consumer example that ships with Intel TBB and report what I find.
Meanwhile, you mention that concurrent_queue doesn't free the memory it used despite deleting the object (also ensuring that the object's destructor is getting called). Is it possible to run your app again and report whether
a) the memory footprint is growing with time? b) Or is it the case that after a point, it remains constant?
thanks for your response. I tried to create a small sample application that reproduces the behaviour. It's appended below. The sample application is single-threaded and it seems to have the same problem.I'm simply creating a huge number of Agent instances. Each of them receives 10 messages which are being deleted again afterwards. However the memory consumption stays the same until I finally delete all the agents.
Regarding your questions:
In the example I've created a loop that repeats the whole process five times. In this case I didn't notice any further memory increase except from the one in the beginning. But in my "real-world" application it seems to consume more and more memory at runtime even though everything's being deleted.
I was referring to different threads, but thanks to the pointers. The threads I found were: