11-01-2014 11:25 AM
Hello,
I have small question about closing references.
When writing some programs I usually open reference in one place store it in some shift register or fgv and usewhen I need like in case 1. Then I close reference on aplication exit so memory leak wont happen.
I wonder why case 2 works fine. I have opened reference used it and then closed. So property where I write 1 shouldn't return error?
Solved! Go to Solution.
11-01-2014 12:04 PM
Can you rewrite your question? I'm not clear what is case 1 and what is case 2. What does "So property where I write 1 shouldn't return error? " mean?
11-01-2014 12:44 PM
Something happened with my image. Here it is:
My question is about handling references in LabView. I have been programming more than 2 years and my habbit always was: obtain references for all objects ( this VI, app, controlls) that I may use in future and close them while exiting program. That is pictured in sequence 1. In that memory leak cant happen ( I hope so :D)
In secound case I close reference. I reffer to the same closed reference later so why does it not give me error?
11-01-2014 01:22 PM - edited 11-01-2014 01:25 PM
I can't see why there wouldn't be an error unless the tunnel creates a duplicate copy. Why are you wiring it that way instead of using the output from the first value to wire into the input of the second reference? Try doing that and see if it errors. If so, the tunnel is likely creating another address. I believe it's the DET that will let you check for leaks. Run this while you test the code on the top. It'll let you know if you have a leak.
But, why is that your habit? I'm confused as to why you would WANT to get into that habit? For both of those examples, you could just wire the new value to the indicator. You never pull the value so there's no need to have it as a control. I realize this is just an example used to illustrate a point. But, I suspect your code is going to get incredibly confusing to read if you're making a lot of these references and using them all throughout the code. If you're not, what are you gaining by using the reference rather than the control/indicator itself?
In your description, it suggests you may not even use some of these references. Why not create a reference only as you need it?
11-01-2014 02:12 PM - edited 11-01-2014 02:14 PM
Read Closing References in LabVIEW
As Natastfw said, neither of your cases make any sense to do that them way.
My take is that if it is a reference that opens itself like wiring the reference constant, you shouldn't have to explicitly close. If it is a reference you explicitly open with the Open Reference function, then you should explicitly close it when you are done.
11-01-2014 02:16 PM - edited 11-01-2014 02:20 PM
I wanted to know why there is no error.
Another example what I mean in VI snippet.
Edit
RavesFan
thanks for link.
It says here that:
Although you should usually close references when you no longer need them, you can leave implicit references and references returned in the reference out terminal of unwired property and invoke nodes open, shown below, because a Close Reference function does not actually close these references or remove the target objects from memory.
So when this reference is closed? What happens if I open multiple implicit references? Are they all closed when app goes to idle state?
11-02-2014 01:46 PM
Implicit references don't really close until the owning VI is closed. So closing an implicit reference won't do anything. Implicit references to the same control will use the same reference.