Jump to content

When to close references?


Recommended Posts

(Apologies if I misuse the terminology. I'm still a little fuzzy on the language of Labview references.)

Labview documentation implies that you only need to close references that you specifically open using the Open VI Reference primative. Is this acceptable programming?

I tend to use a lot of VI Server references to front panel objects in my code. (i.e. I right click on the control and create a reference, property node, or invoke node.) What are the implications of the following:

  1. Branching the reference. When I branch should I close each branch?
  2. Sending the reference to a sub vi. Should the sub vi send the reference back out for the calling vi to close? Is it okay to have the sub vi close it or simply leave it dangling?
  3. References within references. If I use a reference to a cluster to get an array of references to all the controls in the cluster, should I close the references in the array as well as the cluster reference?
  4. Aborting a vi. What happens to references during application development when I abort the vi rather than gracefully closing it?

Reading over my questions I guess it comes down to how Labview deals with copying references and garbage collection. I understand the concept of pointers in text languages but I'm not sure how Labview handles it.

Link to comment

QUOTE(Daklu @ Mar 7 2008, 05:03 PM)

  1. Branching the reference. When I branch should I close each branch?

You only close a reference once no matter how many times it branches or where you send it. Once it is closed, it is closed for all branches. That's the nature of references -- the reference points to the same object and it is only the ref number that is duplicated when a wire branches. This is its power and its curse. In LabVIEW the only time when one section of the code can affect other sections of the code is when references get involved. So if you do close the reference in one branch, or in a subVI, the reference is no longer valid in any other section of the code, and if that other section of code was still supposed to be using the reference, that other section will start returning errors.

Link to comment

QUOTE(Daklu @ Mar 8 2008, 12:03 AM)

Static References (those directly linked to a control) can't be closed. If you close the reference nothing happens. It would be like deleting the control itself.

QUOTE

I prefer to close a refence in the same VI as where I create them.

QUOTE

If it's tied to a real control/indicator it has no use to close.

QUOTE

Don't even think about it!

LabVIEW will try to garbage collect what you created, but sometimes you see window in the upper left corner:

Resetting VI

One caveat if you open a VI reference via 'Owning VI' from a control ref, you have to close the new VI reference.

A good pointer is http://eyesonvis.blogspot.com/2008/03/vi-server-references.html' target="_blank">this.

Ton

Link to comment

QUOTE(tcplomp @ Mar 8 2008, 06:00 AM)

Static References (those directly linked to a control) can't be closed. If you close the reference nothing happens. It would be like deleting the control itself.

Ton

I'd like to ask what you (or anyone) thinks about the situation in the attached picture. This code gets references to 15 different array indicators (of type string, numeric, and boolean). So, do we just need to close the "Tab Control" reference? Perhaps even that isn't necessary? I'm a little fuzzy on what constitiutes a "branch", and if a reference to a control is the same as a reference to an indicator insofar as how it's treated in LV.

Thanks,

Richard

Link to comment

QUOTE(BrokenArrow @ Mar 10 2008, 02:03 PM)

I'd like to ask what you (or anyone) thinks about the situation in the attached picture. This code gets references to 15 different array indicators (of type string, numeric, and boolean). So, do we just need to close the "Tab Control" reference? Perhaps even that isn't necessary? I'm a little fuzzy on what constitiutes a "branch", and if a reference to a control is the same as a reference to an indicator insofar as how it's treated in LV.

Thanks,

Richard

At the bottom of one of the links provided by Toby earlier in this thread, there a a sentance that is similar to the short answer I believe I originally heard expressed by Rolf.

If the reference changes from run to run, then it needs closed. At the time Rolf wrote that we had to type cast to a U32 and look at the number. Since then I BELIEVE you can probe the wire.

So if it is dynamic (changes) close it.

Otherwise it is your perogative.

Ben

Link to comment

I've learned over the years to explicitly close every reference I create. Since I generally am interacting with MS Office applications, this means all of them including the application references from the front panel. When I'm working with VI rerferences or front panel object references, I always close them unless I get a fault and completely understand why I'm getting the fault. This may be overkill, but I don't get memory overflow crashes on my tests that run for months on end any more.

Link to comment

QUOTE(Aristos Queue @ Mar 10 2008, 07:16 PM)

Wow Aristos, thanks a lot for your effort. Looks like I was 50% there, as I'm closing out the array of refs upon leaving the VI, but not the initial tab page references. I guess LabVIEW was doing that for me when the VI becomes idle, which it will for perhaps hours at a time.

Richard

Link to comment
QUOTE(BrokenArrow @ Mar 10 2008, 05:55 PM)
I guess LabVIEW was doing that for me when the VI becomes idle, which it will for perhaps hours at a time.
Yep. LV cleans up all the refnums that LV opens when the VI that opened them goes idle. For the vast majority of programmers, that's enough. But some apps do lots of opens/close in tight loops that run for days/months/years, and others do open-modify-unload and they need the unload to work, so it is important that the refs all be closed. For those 10% of users, knowing when to close is important.
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.