Why Do I Get Invalid Refnum Error -2553 After Calling Significant Number of Storage VIs?

Updated Apr 26, 2019

Reported In

Programming Language

  • LabVIEW G

Issue Details

I have VIs that access channel groups and channels in significant number of files. While I used Close Data Storage Express VIs to close the file Storage refnums opened by Open Data Storage Express VIs, after accessing channel groups and channels in many files repeatedly, I eventually get error -2553, "The object refnum is invalid. The node that returned this refnum might have encountered an error and did not return a valid refnum. The storage this refnum refers to might have closed before the call executed. This error usually is the result of an error being encountered, such as failing to open a storage or looking for a channel that does not exist. Valid refnums become invalid when the storage they refer to is closed." What is causing this error and how can I prevent this error?

Solution

The error is caused by channel group and channel refnums that are not closed in timely manner, causing the memory to run out that prevent new refnums to be created.

One possible workaround is to create an executable to access channel groups and channels. Every time the executable finishes, opened refnums will be closed as well.

Another workaround is to close channel group and channel refnums explicitly using the VI below. Note that this VI is not available before LabVIEW 2018.

<LabVIEW 2018 directory>\vi.lib\Platform\storage\Storage.llb\CloseDataObjectRefnum.vi

Additional Information

Storage VIs use implicit refnum mechanism that refnums will be automatically released when VIs close. When you access many channel groups and channels in a loop, it is possible to keep opening channel group refnums and channel refnums using Read Data and Get Properties Storage VIs faster than they are released automatically. As a result, your code can continue to open refnums until you run out of memory,