Originally Posted by
anduril462
Typically in a producer-consumer model, if the queue is full, the producer stops and waits for the consumer to consumer some data so there is room again. You typically don't want to just overwrite or discard data.
Regardless of whether you follow that model, or the "just throw away data" model, the rule is still: only free memory when you are all done with it and never need to access it again. It's really that simple. If the consumer is done with it, free it. If the producer is throwing it away because the consumer is taking too long, free it.