Queue & memory management

Each task in FreeRTOS has its own stack, and when a task is created, memory is allocated for its stack. Similarly, when a task exits, the memory associated with that task is released back to FreeRTOS. Now, let’s consider a scenario where we have two tasks: Task A sends data to Task B, and Task B receives data using a queue.

How does the queue mechanism handle data exchange between tasks considering memory allocation and deallocation occur when tasks are created and destroyed

A queue has it’s own memory and items are copied in by sender and out by receiver.
So it’s an independent resource not bound to tasks.
When using a queue to transfer pointers to data / items by reference it’s up to you to ensure the required lifecycle of the pointed to data.