From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

closing references - when

Solved!
Go to solution

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? 

0 Kudos
Message 1 of 7
(3,264 Views)

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?

0 Kudos
Message 2 of 7
(3,249 Views)

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?

0 Kudos
Message 3 of 7
(3,239 Views)

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?

0 Kudos
Message 4 of 7
(3,226 Views)

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.

0 Kudos
Message 5 of 7
(3,212 Views)

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:

Exceptions

Implicit References and Unwired Property and Invoke Nodes

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?

0 Kudos
Message 6 of 7
(3,208 Views)
Solution
Accepted by topic author apapasd1sd

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 7
(3,153 Views)