Protecting References in LabVIEW

Have you ever spent hours trying to track down a bug only to find that it was something simple? Or worse: something you didn’t know that you didn’t know. When programming in LabVIEW, a language that simultaneously meets the needs of veteran programmers and neophytes alike, basics can sometime be lost in abstraction; for all the things LabVIEW hides from you it can also create bugs that are seemingly inexplicable and incredibly hard to track down. One of those bugs is when LabVIEW decides to clean up references; which in practice is less a bug and more of a feature.

LabVIEW has two general rules when it comes to references:

  • When a reference is created, it is associated with the VI hierarchy of the VI where the ‘create function’ is located
  • LabVIEW will release/close any references associated with a VI-Hierarchy that is idle.
A VI hierarchy can be thought of as an inverse tree at runtime that describes an initial VI (i.e. ‘’) and all of the VIs that are statically called from within. Calling a VI dynamically will create a ‘new’ VI hierarchy.

This cleaning of references is a kind of ‘garbage collector’ where LabVIEW looks for items that it thinks are no longer being used. This generally affects items that are passed-by-reference rather than passed-by-value. In most cases, normal (non-advanced) LabVIEW programming won’t violate either of these rules; but once you have to create a separate VI hierarchy or launch VIs dynamically where references are created, the life cycle of associated VI Hierarchies become important to achieving certain functionality.

We’ve included three examples providing situations where references can be lost (from simple to advanced), short summaries are provided below, to see these examples in action, download the soure code (LabVIEW 2015) available here:

Example 01: This example shows a simple mistake that can cause you to lose a reference. When a for loop runs zero times, simple tunnels will output the default value of the data type rather than the data that’s wired in; using a shift register will preserve the data if the for loop runs zero times.

Example 01 - Loop Snippet

Example 02: This example provides a handful of situations where references can be come invalid when launching a VI dynamically.

Example 03: This example shows a solution for preserving a reference created in another VI hierarchy using the run VI method and how to keep it alive while in use. This method mirrors the functionality of the proxy caller when using the asynchronous call functions.

Recent Posts:

MWD Basics: Accelerometers Part 2
Publish Date 05 Apr 2017 Nathan SzantoAntonio Alexander

In Part 1 of this post, we used the idea of shining a light through a cut-out in a [..]

Employee Profile: Meet Kelsey
Publish Date 05 Apr 2017 Shannon HayesAntonio Alexander

Today we sat down and talked with one of our Erdos Miller employees to learn about [..]

MWD Basics: Accelerometers Part 1
Publish Date 05 Apr 2017 Nathan SzantoAntonio Alexander

In a previous blog post on the building blocks of an MWD system, I mentioned that [..]

Basic Static Structural FEA TIPS
Publish Date 05 Apr 2017 Garret HallmarkAntonio Alexander

Finite Element Analysis (FEA) can seem like magic when you first use it. The program [..]

Three Building Blocks of an MWD System

  There is often a point early in the learning process where the student knows so [..]

Employee Profile: Meet Rohama

Today we sat down and talked with one of our Erdos Miller employees to learn about [..]

Popular Posts

Posts by Topic

See All Topic