Solution
When using queues in LabVIEW the
Memory is Full error is presented in scenarios where the producer loop enqueues elements at a faster rate than the consumer dequeues them, if there is an important difference in loop rates, the elements that are not dequeued will be stored in the PC memory, starving the resources and eventually causing the error. The following are some strategies to avoid that error:
- If the application allows it, consider decreasing the rate at what the producer loop enqueues item, Wait functions can be used to achieve that task.
- If the processes of the consumer loops do not need to be completed immediately, consider just doing some of the fundamental tasks there and then writing down the values on a file for later processing/analysis, if you can reduce the amount of code in the consumer it will speed up the execution and avoid falling behind the producer rate, this will help dequeuing faster. In the LabVIEW How To: Block Diagram section of the LabVIEW Product documentation you will find different options for writing files.
- You can set a maximum size on the queue using the max queue size input of the Obtain Queue Function, this will cause the code to execute differently depending on whether a timeout is set on the Enqueue Element Function or not, both will avoid the memory full error.
- If the timeout in ms (-1) is not wired or is -1 in the Enqueue Element Function and the queue is full, the producer loop will slow down and wait until elements of the queue are removed by the Dequeue Element Function to enqueue a new element.
- If the timeout in ms (-1) is wired with a positive value in the Enqueue Element Function, the queue is full, and also the timeout is reached, the Enqueue Element Function will continue enqueing elements as usual overwriting the last ones.
- You can use the Flush Queue Function along with the Get Queue Status Function to flush the elements of the queue, this solution is not ideal since it will remove all the elements immediately from the queue, however, it can be useful in case you see the number of elements in the queue constantly increases. You can configure a maximum number of elements in the queue before flushing and use a case structure to complete the task as shown below, this will empty the queue for later use:

Note: after removing elements from the queue elements cannot be accessed from other queue functions, you will get what elements were removed using the remaining elements output of the Flush Queue function, consider writing those elements to a file if needed.