From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Should the reference be closed on read-file error, or not?

Solved!
Go to solution

Dear users,

 

when I read a file a reference is created an a should close it, when not needed anymore, should I? Below is a minimalistic example to my next serious question: Should I close the reference on read-file error, or not? Is there any created in the case of "file does not exist"?

 

no error - close reference.png error - do nothing.png

 

Cheers,

0 Kudos
Message 1 of 7
(2,618 Views)
Solution
Accepted by ghighuphu
No, when used in this way, the references created by the file read and write functions do not need to be closed -- thought it would have no negative effect if you did.

Also, you don't want or need the case structure around a reference close function.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 7
(2,605 Views)

This was a minimal example and there is some (relative) resource extensive data manipulation (in the CASE structure). That's the reason for the


@mikeporter wrote:
Also, you don't want or need the case structure around a reference close function.

 

0 Kudos
Message 3 of 7
(2,595 Views)

The Read and Write File functions will automatically close the file if you do not wire the reference out to anything.  Given your example, that's what I would do.  But in a general case, always use the File Close if you are doing more than one function with your file.  The Close File will run even if there is an error coming into it.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 7
(2,580 Views)

If you are done with the file, then I would vote for explicitly closing the file.  The performance hit is negligible, but your code will be clearer to read.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 5 of 7
(2,576 Views)

@crossrulz wrote:

The Read and Write File functions will automatically close the file if you do not wire the reference out to anything.  Given your example, that's what I would do.  But in a general case, always use the File Close if you are doing more than one function with your file.  The Close File will run even if there is an error coming into it.


Building on your information, I should use "close file" in both cases. Because once I wire out the reference, it exists and should be closed. Or to put the "close file in front of (outside of) the CASE structure"

Thank you for your suggestions!

0 Kudos
Message 6 of 7
(2,548 Views)
Solution
Accepted by ghighuphu
...or put the close before the case structure.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 7 of 7
(2,520 Views)