09-10-2014 02:13 AM
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"?
Cheers,
Solved! Go to Solution.
09-10-2014 03:11 AM
09-10-2014 03:31 AM
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.
09-10-2014 06:45 AM
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.
09-10-2014 06:52 AM
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.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
09-11-2014 01:38 AM
@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!
09-11-2014 11:21 AM