LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to close reference to SystemResource?

Solved!
Go to solution

Hello, I have a problem with reference leak. Running this VI leads to significant memory usage increase (10MB/s) due to unclosed references to System resource. My first try to solve it was to wire Close reference VI to SystemResource, but the wire is grey and there is an error Wire: Class conflict. Since I am not familiar with classes in LabVIEW, I don't know how to overcome this problem.

 

In my app, system resources are read every 10th of the second on cRIO and after 10 minutes the app crashes. I know about the other options like FGV with Init and Read, or shift register from parent loop (this VI is meant to read it only once), but I hope there must be neater way to do it. Or am I wrong?

 

Thanks.

image.png

0 Kudos
Message 1 of 4
(2,769 Views)

Are you really need new SystemResource 10 times per second?

Take it once and use by wire.

0 Kudos
Message 2 of 4
(2,762 Views)
Solution
Accepted by topic author Thomas444

Two possibilities;

 

1) Use the Close function from the System API palette. That one knows how to close this type of refnum properly.

 

2) Put the Refnum constant outside the loop and wire it into a shift register. Then wire the left shift register to the property node refnum in, and the property node refnum out to the right shift register. Those named refnums are a special beast as they do contain a hidden internal refnum once initialized but since you do not wire that back to the refnum input it will create a new internal refnum each time. Close the refnum anyhow using the method in 1) after the loop terminates.

 

2) is highly preferable as opening a new System API refnum not only uses up memory but also takes a significant execution time that is not necessary to be incurred on every loop iteration.

 

And ohhhh yes! Add some form of delay inside the loop. As is, it will tend to monopolize the CPU core on which it is running by running as fast as possible. With the current code that may not seem so bad since the inherent (re)opening of the refnum will slow down the loop considerably but once programmed properly that loop will blaze away and heat up your CPU unnecessarily.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 4
(2,758 Views)

As I thought about it more and more, i somehow figured that opening it for every reading is probably not the best solution. I wanted to avoid wiring it from parent, but I guess it is the only viable option. Thank you guys for help.

 

And yes, I use delays 🙂 It was just to make the memory loss effect more apparent for observer.

0 Kudos
Message 4 of 4
(2,732 Views)