05-30-2010 09:50 PM
If you open references to a LabVIEW object, such as an application,
control, or VI, close the references by using the Close LV Object
Reference function. Otherwise, the reference stays in memory even
though the VI no longer uses it.
The above quote is from Development Guide from NI. I realized that I have been using references without closing them. Even though I have never encountered any problem, I decided to add close reference to my programs. My question is, should I put the reference and close reference vis both in a while loop and open/close every iteration or should I use open reference in front of a while loop and close it after the while loop, this way, I will have to use a shift register to keep the reference. Or whether there are some other options. Can someone give some advice?
Thanks in advance,
Guangde Wang
Solved! Go to Solution.
05-30-2010 09:57 PM
Open and close your references outside the loop (i.e. open the ref previous to the loop, and close it after the loop is finished executing). Repeatedly opening and closing the same reference inside a while loop is pointless, and takes up unnecessary overhead.
Also, since the reference doesn't change with each iteration of the while loop (unless you are doing something to it specifically?), you don't actually need a shift register. You can use one if it makes you happy, though.
d
05-30-2010 10:50 PM
Dianes,
Thank you for responding to my post. I did notice that the reference numbers are not changing, even if I stop the program and start it again. It's good to hear that I don't have to use a shift register to keep the value. I will do it as you suggested.
Thanks again,
Guangde Wang
05-31-2010 02:00 AM
The fact that you didn't encounter problems with keeping the refs open is because LabVIEW has some quite good garbage collection.
In the case of a for loop you should use shift registers, because a for loop can run zero (0) times after which you will have a NULL-reference.
Ton
05-31-2010 09:29 PM
Ton makes an excellent point about FOR loops, since they can execute 0 times. If you are using a WHILE loop, though, you don't need the shift register.
Thanks for pointing that out, Ton!