LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory leak (probably due to timer)

Solved!
Go to solution

Hi all,

 

I'm having trouble resolving a memory leak in a VI that I'm running. I know which small part of the VI the memory leak is occurring in and have attached it, as well as a similar VI that has no memory leak. I would really appreciate any help solving it. I'm running the VIs on a PC without LabVIEW, using an installer.

 

Unfortunately I can't use the VI without the memory leak since it sprays continuously after exactly 10 hours, and only changes the spray state at integer multiples of the spray time (so if I set spray time=30 and wait time=70 I will get spray time=30 and wait time=60 when the VI runs). I also need the VI to run for up to 72 hours so the 10 hour problem is a big one and what caused the changing of some of the spray code.

 

Thank you in advance for your help, and please let me know if there's any other information I can provide

Download All
0 Kudos
Message 1 of 7
(3,756 Views)

Hi Neil,

 

I'm having trouble resolving a memory leak in a VI that I'm running.

It would help when you don't create a new task with each iteration of your loop.

It would also help to close any reference which you have opened before…

 

Did you look at any of all those DAQmx example VIs coming with LabVIEW? They explain how to use those functions very well…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 7
(3,732 Views)

Hi Gerd, thank you for your help.

 

No I haven't looked at the DAQmx example VIs, I didn't build this VI and this is my first time working with them. I'll look at them now, are there any specific ones that would be most useful for me to go over?

However, I don't think the problem is to do with the DAQmx part of the VI, the only part that is different in the VIs I attached is the part that sets up the spray/wait timing. This makes me think that the leak is coming from the Elapsed Time2 express VI - but I don't see how a timer can give me a memory leak of 0.1Gb per 10ish seconds!

 

As for your other suggestions I'm afraid I don't know how to implement them, would you be able to guide me in the right direction please?

 

Thank you again for your help

 

0 Kudos
Message 3 of 7
(3,725 Views)
Solution
Accepted by topic author Neil_C

Hi Neil,

 

so somebody told you to work with LabVIEW and you haven't bothered to learn the basics before doing so?

 

check.png

I moved the content of the subVI into the main VI and call the init stuff just once before the loop.

In the loop you should add a small delay to prevent the loop from spinning as fast as your CPU allows.

And I added a function to clean up the DAQmx task once you stop the loop.

 

When you learned the basic DAQmx stuff you might even simplify the init part to one function…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 7
(3,716 Views)

Hi Gerd,

 

Unfortunately I am the only person who has ever used LabVIEW here (albeit only once whilst I was still at school) since the person who made the VI left a year ago. As such I'm trying to learn how to use it whilst also trying to solve the problems - not an ideal situation but one I have to try my best in!

 

Thank you for the image, you solved the memory leak for the VI, now to check if there's still any problems when I put it in with the rest of the complete VI. Also I now understand what you did and why you did it. Thank you for the link as well, I'll work through that now.

 

What I don't understand is why there was never this problem with the memory leak before in the previous VI - it was still initializing the task within the loop and not closing it, but never had a memory leak problem?

 

I'm also not 100% certain about the time delay and how it works with the timers within the loop -  why would I need the loop to execute more than once whilst the VI is running? In other words I'm not sure how it works with the loop executing and the elapsed time continuing instead of restarting? Presumably adding in this timer before would have reduced the severity of the memory leak? I'm also not sure whether it adds a 100ms error to the spray time and the wait time, I don't think it does since only the clear task is outside of the loop after it but I'd just like to check.

 

Once again thank you for your help, I really do appreciate it

 

0 Kudos
Message 5 of 7
(3,677 Views)

You can certainly eat up memory quickly when the VI is creating resources in a loop that is running as fast as it can.

 

The difference between your two VI's:

1.  Memory leak - runs as fast as it can, there is no delay in that loop.  It is probably running thousands of iterations or more per second.

2. No Memory leak - has a Time Delay Express VI set for 5 seconds, so it is only running 5 seconds per iteration whenever that True case is running.  It is actually still leaking memory because of the subVI creating a task, but it is happening thousands to millions of times slower that you just haven't waited around long enough for you to notice the leak.

Message 6 of 7
(3,617 Views)

Awesome, thanks for your help, that makes perfect sense. Looks like I've got a lot more code to change then!

0 Kudos
Message 7 of 7
(3,548 Views)