drjdpowell wrote:
LabVIEW doesn't have a "garbage collector" and I don't believe it is possible to add one easily like one can in an "everything has a reference" lanuage. Garbage collectors, I believe, increment over all object references and find objects not refered to by any other still-live object. That doesn't work in LabVIEW. The "die with your creating hierarchy" thing works well in the large majority of programs that don't asynchronously call VI's.
Why are you using a DVR, by the way? There are other ways in labVIEW to hold common data, such as an "Action Engine".
C is an ""everything has a reference" language". It is not easy to add a garbage collector to C because this requires (in my opinion) an asychronous thread. You can write an garbage collector in C, but this is not easy even for simple applications. At least you have to fork(); and you should have fork();ed also for other reason.
How and when objects are destroyed is subject of the memory managment strategy. One way might be to increment over the user of the object references. But there are other. If you have only this specific strategy in mind I admit that LabView hasn't a garbage collector.
I am using DVRs because I want to share information between groups of instances of a class. I have learned from the previous (first) question in this forum, that it is very easy to create a copy from a class.
In another part of my application I provide a registration service for classes based on DVRs. Like this the registration service can see immediatly if a class is idle, for example.
A global variable or a finite state machine can solve this too I think. But I don't use global variables at all, because I want to define for every data the minimum scope. In my opinion global variables mess everything up and have a high risk of unwanted side effects. Due to this FGVs are also an anti pattern for me, although I know that many better programmer than me use them. This can be a problem of DVRs too and I try hard to limit this.
Finite state machines are a nice invention, but I do not like the LabView design from 2007 and I would prefer a object oriented approach since my application is already to big to maintain single VIs.
Since I use a lot of asynchronous calls, mostly I do not even collect data from them (Flag 0x80), and the VIs I call asynchronously are determined dynamically, the garbage collection strategy of LabView does not work for me.