From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Avoiding memory leaks in queues

Hi, I am using queues to perform certain file writing operations. Since my data writing rate is faster, I am enqueueing the data first and after a certain interval, I am 'Flushing' out the queue and writing the data to a file. I am performing this operation using 2 seperate loops, one loop for enqueuing and another loop for flushing.  

 

But when I check the memory (labview execution trace toolkit), I find that that the 'memory allocation' is being done but there is no 'memory free'. And because of that, the memory size is increasing rapidly.

 

Could you guys plz help me out in making the memory usage stable.

 

I'm initializing the queue before I begin the actual logic execution and destroying the queues only after while I am exiting my application.

 

Looking for your answers/suggestions in anticipation.

 

Sreedhar

0 Kudos
Message 1 of 12
(4,113 Views)
can you post an example to demonstrate this?  Something isn't obvious here-  the queue should empty.  Is the file large?

"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 12
(4,094 Views)

Hi, the file size isn't very large at all. I am having a condition where I am checking if the queue size is more than 60 elements and whenever it exceeds 60, I flush it out.

 

I do not have the code here as the code I have developed is on a remote domain (no internet). However, I will try to build a replica of it and provide it to you.

 

Meanwhile, can anyone still give me some pointers where I need to take care.

 

-Sreedhar

0 Kudos
Message 3 of 12
(4,080 Views)
I'd like to see an example because I'm thinking another issue may be tricking you into thinking its the queue.  In the meantime you could look at the "lossy Queue" example that ships with LabVIEW and see if that may be a suitable for your use.

"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 12
(4,058 Views)
You may have to force the VI to release the freed memory. If memory serves me correctly LabVIEW will not automatically release memory that it has allocated since it may need to use it again. We an into a similar issue with TestStand and we had to force the release of memory at various points in our very large test sequence.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 12
(4,043 Views)

Hi Guys... thanks for your answers. However, I think I found the solution. LabVIEW keeps allocating memory upto the max size of the queue. It then starts freeing the memory. In my case, I gave the max queue size as 1000 and was flushing out as soon as the queue size exceeded 60. So, I reduced the max size to almost 100 and flush after 60.

Now when I check in the execution trace, the memory free is happening.

 

Hope this will be helpful to others who are stuck like me.

0 Kudos
Message 6 of 12
(4,025 Views)

A little more mn freeing up memory.

 

Yes LV will keep any memory it has allocated unless we explicitly fee it up or the VI goes idle and house keeping frees the memory. But just because LV has allocated for the queue does not mean it is not available for other tasks once the queeu is flushed. THe next time the queue get filled those buffers will be used if they are available and large enough and might as well throw in "contiguous" while I am at it. Now if LV just kept allocating more without re-using the olds stuff, then we're leaking.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 12
(4,017 Views)

Ben, could you pl provide a better picture of what you were trying to say?? I understood the part in which you said that LV will free the memory if the VI is idle or if we clean up the memory by ourselves. But what were you trying to say with queues ?

 

In my case, I was initializing the queue in my constructor and destroying it while I exit the application.

 

So what I assume is, all the queue size was getting utilized for once and then it continuously starts freeing the memory. LV keeps on allocating whenever a new element is enqueued but also frees the memory after the flush operation.

0 Kudos
Message 8 of 12
(4,013 Views)

Sreedhar T wrote:

Ben, could you pl provide a better picture of what you were trying to say?? I understood the part in which you said that LV will free the memory if the VI is idle or if we clean up the memory by ourselves. But what were you trying to say with queues ?

 

In my case, I was initializing the queue in my constructor and destroying it while I exit the application.

 

So what I assume is, all the queue size was getting utilized for once and then it continuously starts freeing the memory. LV keeps on allocating whenever a new element is enqueued but also frees the memory after the flush operation.


Nope.

 

The memory is is initialized "Allocated" when you initialize the queue with a 1000 max size (all 1000 elements are there but may have empty data)  Flushing the buffer just puts empty data in the queue buffer and does not change the queue buffer size. 

 

To free memory the buffer must be "dealocated" not "flushed" the destroy queue dealocates the buffer and releases the memory.

 

So when you changed the max size of your queue from 1000 elements to 100 elements you reduced the buffer size by 10x

Message Edited by Jeff Bohrer on 03-09-2010 12:41 PM

"Should be" isn't "Is" -Jay
Message 9 of 12
(4,005 Views)

But as per the labview execution trace toolkit, it is showing "memory free" after performing the flush operation. As an information, I have used the queue in an LV2G.

 

I will try to destroy the queue as soon as I perform the flush and see the memory difference.

Just a piece of advice that I want, would you tell me the implication on performance (CPU usage) if I use the queue destroy so often?

 

Thanks

Sreedhar

0 Kudos
Message 10 of 12
(3,970 Views)