Daklu Posted March 8, 2008 Report Share Posted March 8, 2008 (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: Branching the reference. When I branch should I close each branch? 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? 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? 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. Quote Link to comment
TobyD Posted March 8, 2008 Report Share Posted March 8, 2008 QUOTE(Daklu @ Mar 7 2008, 03:03 PM) (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? There is some good info here and here. Quote Link to comment
Aristos Queue Posted March 9, 2008 Report Share Posted March 9, 2008 QUOTE(Daklu @ Mar 7 2008, 05:03 PM) 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. Quote Link to comment
Ton Plomp Posted March 9, 2008 Report Share Posted March 9, 2008 QUOTE(Daklu @ Mar 8 2008, 12:03 AM) 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:Branching the reference. When I branch should I close each branch? 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 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? I prefer to close a refence in the same VI as where I create them. QUOTE 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? If it's tied to a real control/indicator it has no use to close. QUOTE Aborting a vi. What happens to references during application development when I abort the vi rather than gracefully closing it? 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 Quote Link to comment
Daklu Posted March 9, 2008 Author Report Share Posted March 9, 2008 Thanks for all the info and tips. I understand Labview references much better now. Quote Link to comment
BrokenArrow Posted March 11, 2008 Report Share Posted March 11, 2008 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 Quote Link to comment
LAVA 1.0 Content Posted March 11, 2008 Report Share Posted March 11, 2008 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 Quote Link to comment
Lars915 Posted March 11, 2008 Report Share Posted March 11, 2008 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. Quote Link to comment
Aristos Queue Posted March 12, 2008 Report Share Posted March 12, 2008 My comments are in the image. Quote Link to comment
BrokenArrow Posted March 12, 2008 Report Share Posted March 12, 2008 QUOTE(Aristos Queue @ Mar 10 2008, 07:16 PM) My comments are in the image. http://lavag.org/old_files/monthly_03_2008/post-5877-1205190996.png' target="_blank"> 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 Quote Link to comment
Aristos Queue Posted March 12, 2008 Report Share Posted March 12, 2008 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.