LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Where when and why should we close references

Hi Gabi1,

repeatedly opening and closing ref's will eat up memory because there are resource allocated for each open. The close does not delete these resource (memory) but only marks them as availbe for deletion. The clean-up only happens when the VI goes idle.

So...

Open outside the loop and close ONCE after the loop.

And yes, writing to a local is prefered because locals do not have to switch to the UI thread to work.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 11 of 14
(1,037 Views)
the close reference is like removing a pointer from the address space?
that'd make sense, but then why would we see a performance difference between when we do versus when we do not close the refs?

it seems that either way this is answered it'd be a good idea to use the request deallocation function in all subvi's when they are closed, assuming that "unused memory" would include previously referenced (but now closed) address space, and all the copies of local variables, and structure copies, etc...
but even if it only gets some of it, its better than getting none

would someone clarify for me the pros and cons of using the local variable verus the property node "value"?
from other languages i've used passing things by reference instead of by value was most of the time going to use less resources, both processor and memory

and something I've found is that instead of sending a pipe across a structure border, if i write to a local or property, then read from it on the other side, there is less memory used, of course this opens up more chances for race condition to occur
an idea i've not played with is to pass references to objects across the structure borders instead of the above

BTW I use 7.1.1

Message Edited by jccorreu1 on 08-24-2007 07:34 PM

0 Kudos
Message 12 of 14
(1,020 Views)

thanks guys for the answers. i am still quite a bit confused, but the rule seems to be:

Always close a reference!

thats a bit too bad, because that means cluttering up quite a bit the code, either with wires to the references and a lot of connections to the loops, or with request deallocation icons all over! according to what  i understand that would not even help actually.

so if i have a program with say 50 controls and indicators, in order to access them i will need 50 (!!) reference wires that enters the loops, the event structure, and so on...

so here is my questions:

1) do we have possibility to have pointers to variables?(never saw any such thing in LV)

2) if i have a local in a loop, is the variable duplicated only once, or every time the loop perfoms? if the first is true that would mean it is just generally much better to have locals than references (for cases where applicable). if the late is the right one, then we are doomed to horrible wiring using the references...

 

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 13 of 14
(1,006 Views)
The message about local variables is that they should be used as sparingly as possible. If it is possible to transfer data by using a wire, then that is what you should do. If you are polling a local variable in a loop it does not make a copy of the data every time around the loop. A copy is made for every seperate local variable you have on your block diagram, though.

For your question regarding points, you are correct, there are no pointers in LabVIEW.
Nick R
NI
0 Kudos
Message 14 of 14
(964 Views)