LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Noob question about variable persistance in subvi's

Labview is exhibiting a behavior that I find a little odd. When leaving a subroutine most text programming languages detroy references to any values that are created locally, effectively resetting them. But with Labview, it seems like controls and indicators are automatically created as 'static' variables. The values persist through consecutive calls to the same vi.

Is this really the default behavior? I've searched the documentation and forums for rules regarding scoping and persistance, but I have only found bits and pieces that I have been trying to put together. Is there a concise set of rules explaining when values persist and when they do not?

So far what I've been able to surmise is this:

1. Internal values in sub vi's persist through multiple calls. (I think this is right... when is a sub vi removed from memory?)
2. If a sub vi is called dynamically, internal values do not persist.

Corrections and/or additions are appreciated.
0 Kudos
Message 1 of 3
(2,888 Views)
Very good questions.  Some search terms that should help:

memory management
reentrant subVI
Message 2 of 3
(2,874 Views)
Thanks for the search tips. I eventually found many of the answers under the topic "VI Memory Usage." I don't understand all of it (yet) but it did explain many things I was wondering about.

One thing in particular that was confusing me was the behavior I was seeing when indicators are placed inside case statements. Then I read this:

Conditional Indicators and Data Buffers

The way you build a block diagram can prevent LabVIEW from reusing data buffers. Using a conditional indicator in a subVI prevents LabVIEW from optimizing data buffer usage. A conditional indicator is an indicator inside a Case structure or For Loops. Placing an indicator in a conditionally executed code path will break the flow of data through the system and LabVIEW will not reuse the data buffer from the input, but force a data copy into the indicator instead. When you place indicators outside of Case structures and For Loops, LabVIEW directly modifies the data inside the loop or structure and passes the data to the indicator instead of creating a data copy. You can create constants for alternate cases instead of placing indicators inside the Case structure.
Message 3 of 3
(2,859 Views)