Is there any way to prevent LabView from cleaning up reference when a VI closes? I am in the middle of a development that does a lot of dynamic calls and the garbage collector has bitten me several times and I really do not like to fixed that have been implemented as a work around. One being a VI that holds a references to the vis that is always running. Its only purpose is to keep references alive and is dynamically called and executing on its own. I really hope someone has found a clean way to keep a vi reference valid after the creating vi stop executing.
I have never had a need to save VI references as you have described. I have however stored object references in a Global Variable. This has been helpful when I wanted to store a reference to and array or cluster and then pass them along to other VI's when they were opened. I hope this idea can help.
One of the main principals of using dynamic VIs is that they only stay in memory when being used (therefore reducing memory usage). The only way to guarantee they will remain open is to use a mechanism to save all the VI references until they are no longer needed. A LabVIEW 2 style global variable which stores an array of references may be the easiest to implement.
One other option is to call all the subVIs statically in the VI. This can be accomplished by encasing all the subVIs in a case structure's false case and then wiring a true constant to the case selector. This method will load all VIs into memory but not call them from there static calls.
Thanks for the info. We currently have something we call a server that is running all the time that we use to store references so they do not die. I just think this is sloppy and and an unneeded piece of code. We definitely do not want to embeded the sub VIs as it will lead to added code maintance. We actually are moving away from the case structure type of code to dynamic code. I was hoping that there was a way to have a reference that is Labview scope. I believe active x references are labview scope and will not die when a vi stops execution. I have no idea if it is even possible to call a specific vi with an active x reference. In general the reference issue would not be a problem for us until we went to teststand and now call a station init vi that has dynamic calls to class style creates. With labview 8 supporting classes I hope that the provide a way to keep references alive while labview is running.
In LabVIEW >7 (maybe 6.1) the Run VI method has a boolean input AutoDisposeRef. Wire it to TRUE and the reference will detach from the opening VI and will be automatically closed when the run VI will terminate.
Actually both situations are my problems. We call a create vi that has an "attribute" vi that holds the class parameters. we need to keep that attribute vi reserved for execution or we lose all the stored attributes. With test stand not only does the dynamically called vi stop execution but the station init vi that does the calling also ends so our references are invalid. We needed to create our reference holder vi to run at all times to keep the references valid. I just wish it was cleaner.