A reference number, or refnum, is a unique identifier that LabVIEW creates for an open object, such as a file, device, or network connection. Refnums identify objects for operations while the objects remain open.

All operations you perform on open files, devices, or network connections use the refnums to identify each object. Use a refnum control to pass a refnum into or out of a VI. For example, you can use a refnum control to modify the contents of the file that a refnum is referencing without closing and reopening the file.

Because a refnum is a temporary pointer to an open object, it is valid only for the period during which the object is open. If you close the object, LabVIEW disassociates the refnum from the object, and the refnum becomes obsolete. If you open the object again, LabVIEW creates a new refnum that is different from the first refnum.

LabVIEW remembers information associated with each refnum, such as the current location for reading from or writing to the object and the degree of user access. As a result, you can perform concurrent but independent operations on a single object. If a VI opens an object multiple times, each open operation returns a different refnum.

Refnums can be strictly typed or weakly typed.

LabVIEW allocates memory for an object that is associated with a refnum. Closing a refnum releases the object from memory. Follow these recommendations to use the memory for refnums most efficiently:

  • Close refnums as soon as you are finished with them. LabVIEW automatically closes refnums for you when a VI finishes running, but it is a good programming practice to close refnums as soon as you are finished with them.
  • Close refnums in the opposite order that you opened them.

    For example, consider a program that does the following:

    1. Obtains a refnum to object A
    2. Invokes a method on object A to obtain a refnum to object B

    In this case, close refnums in this order:

    1. Close the refnum to object B
    2. Close the refnum to object A
  • If you open a refnum inside a For Loop or While Loop, close the refnum for each iteration of the loop.

    LabVIEW repeatedly allocates memory for the refnum and does not free the memory until the VI finishes running.