01-12-2016 06:24 AM
Hi
I'd like to ask... should I close the reference of the Workbook in the following code?
In fact, I have little idea whether to close a reference or not, since I thought LabVIEW will automatically close all the references after the execution.
I also found someone said the references of activeX should be closed on my own.
Could someone correct my understanding of closing reference?
Solved! Go to Solution.
01-12-2016 07:44 AM
01-12-2016 08:20 AM
In this case I'm pretty certain the cleanup VIs will close those references so I don't think you need to close them your self. One way I usually test this is I put the code in a while loop, or use the continuous run button. This is basically the only time I ever use it and I only do on small subVIs like this. I then run my code over and over again and look at the task manager to see how much memory LabVIEW.exe is using. After a few seconds if there is a memory leak then memory will continue to increase. If memory goes up and down a little, but overall doesn't continue to grow, then all references that need to be closed, are being closed.
There is an NI white paper on closing VI Server references which is exactly what you are doing but has some relevant information.
http://www.ni.com/white-paper/14393/en
And some discussion on it.
https://lavag.org/topic/16443-closing-references-in-labview-new-documentation-published/
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
01-12-2016 04:37 PM
The answer is -- NO, do not close the Reference. Why? You should not have a reference!! Do not use ActiveX if you don't have to -- there's a perfectly good "Save Report" function that will handle the Save for you, and handle the references as well.
This differs from your example in several ways.
Notice that I did not close the reference, as advertised ...
Bob Schor
01-12-2016 05:45 PM
William1225 a écrit :
Hi
I'd like to ask... should I close the reference of the Workbook in the following code?
In fact, I have little idea whether to close a reference or not, since I thought LabVIEW will automatically close all the references after the execution.
I also found someone said the references of activeX should be closed on my own.
Could someone correct my understanding of closing reference?
I agree with Bob that in this case you shouldn't even use the GetActiveXReferences.vi.
In my opininion you should NEVER close the references you get from the Get ActiveX References.vi and let the Dispose Report.vi close these references. If you open references to other objects then you should close these ones (e.g. a reference to a range on a worksheet) when they are no longer needed.
As an exemple, if you close the sheets reference you got from the Get ActiveX References.vi and then use a RGT vi that uses this reference you will get an invalid reference error.
Ben64
In the following exemple the _Worksheet reference is not closed but the other ones are.
01-13-2016 09:11 AM
Hi mikeporter,
Very thanks to your suggestion:)
Your suggestions are always helpful.
Closing references saves much effort without tracing which reference should be closed.
However, it appears a little redundant if it is not necessary
01-13-2016 09:14 AM
Hi Hooovahh,
Very thanks to your reply.
The links are helpful, I should read it earlier
01-13-2016 09:31 AM
Hi Bob_Schor,
You're totally right, I can't believe I didn't see the Save Report.vi...
I'd originally like to keep the report open and save the data in the file, but when I wire a false constant with the "close report?" and a true constant with the "save change?" in the Dispose Report.vi, it failed and the Help said "The VI ignores this input(save changes?) if the Close Report input is FALSE."
Then I'd realized I have to add the save function before the Dispose Report.vi.
And your suggestion about wire the path in the Save Report.vi is a great idea, I'd never thought of it.
Very thanks to your suggestions!!!
01-13-2016 09:38 AM - edited 01-13-2016 09:41 AM
Hi ben64,
Your explanation is quite clear.
I feel all the replies of this post are very helpful to correct my understanding in different aspects
I hope it is okay that I've marked many "Accept as a solution"
Thank you very much!!!
01-13-2016 09:54 AM
@William1225 wrote:
I hope it is okay that I've marked many "Accept as a solution"
It's fine as long as there really are multiple solutions. Here is a quote from the unofficial guidelines.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord