Hello all,
In the following code I have tested the amount of ram the program consumes, and I realized that when the second loop was executed, the memory is not being freed until the program ends.
Well, you're definitely deleting the pointers, so that's not the problem.
Unless you tell it otherwise, std::queue will use std::deque internally. std::deque is similar in some aspects to a vector. For example, it doesn't shrink back as you remove elements from it.
You can try this: