> I wanted to find out how LabVIEW manages references...
Unfortunately, this depends a bit on which version of LV you are using.
It was changed for LV6.1 to ensure that front panel object references
wouldn't cause memory leaks, or more correctly, memory hoarding.
In LV6, the guideline is to close the reference the same number of times
you opened it or asked for its value. Opens are easy to spot. The
asking needs some more explanation. When you read the Controls[]
property for a cluster or the panel, you are asking the cluster or panel
to provide you with a bunch of references. In LV6, these were unique
references each time they were asked. If you do not want these
references to build up, your diagram needs to call Close on each of the
asked or opened references. Technically these aren't a leak since LV
still knows that they are allocated, and when the top-level VI finishes,
LV will clean them up. But in applications where the top-level VI run
continuously, then this hoarding of memory is the same as a true leak.
The size of the leak per reference is something like 20 to 40 bytes, so
not huge, but still a leak/hoard.
In LV6.1, the asking for references changed. They always return the
same reference, and it is a reference that cannot be closed by the user.
Trying to close it is not an error, but it will be ignored. This
means that the first time someone wants a reference to a control, a
reference is generated, and it will be the reference that is returned
everytime someone asks for the control reference. If your diagram calls
close already, no harm. If your diagram doesn't call close, no harm.
When this panel leaves memory and the reference no longer makes sense,
it will be torn down.
I need to make it clear that the new LV6.1 behavior is for control
references that are asked for. References returned from Open are the
same as before and should be Closed. So this doesn't affect VISA, File
I/O, and other types of references, it is specific to front panel
references.
In case it still isn't clear why the behavior changed, we started seeing
many diagrams written such that they leaked or hoarded memory. In
reality, spotting where a diagram asks for a reference is hard, and
everyone was missing them some of the time. So we changed the
implementation to be more forgiving. The downside is that LV now hoards
one reference and you can't tell it that you are totally finished with
it, but it is no longer a leak.
I hope this sheds some light. If you have additional questions, just ask.
Greg McKaskle