Reference data type

From LabVIEW Wiki
(Redirected from PolyVI Refnum data type)
Jump to: navigation, search

Reference data types, also known as "Refnums", are temporary pointers to open objects. It is valid only for the period during which the object is open. When the object is closed, 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 allocates memory for an object that is associated with a refnum. Close the refnum to release the object from memory.

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, so 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. 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 to most efficiently use memory and other resources. Close refnums in the opposite order that you opened them. For example, if you obtain a refnum to object A and invoke a method on object A to obtain a refnum to object B, close the refnum to object B first and then close the refnum to object A.

For many objects leaving refnums open or constantly opening new refnums can lead to memory leaks. Therefore, the rule is to only keep the refnum as long as it is needed and close it when it is no longer needed. An exception to this rule is for the GObject class and anything that inherits from it in the VI Server Class Hierarchy. Attempting to close one of these refnums which is still in use because the owning VI is still open will no-op, or not operate, and will not close the reference. LabVIEW automatically closes these refnums when they are no longer needed through its internal memory management and garbage collection.

Reference Types

See Also

External Links