05-31-2019 08:59 AM
See picture attached:
I have a loop that runs likely indefinite, and i have some .NET invoke nodes inside.
How do i wire this up in the best way ? I want to avoid memory/reference leaks + unneccesary overhead as much as possible.
Is one of the two options on the pic an option or is there any better solution?
Solved! Go to Solution.
05-31-2019 09:18 AM
Create and destroy the reference outside of the loop. Use a shift register to keep the reference in the loop.
So technically, both options you show aren't the recommended way...
However, the top one with exchange of tunnels to shift register is the recommended way.
06-08-2019 12:37 AM
why a shift register ? the reference keeps always the same, even without.
06-08-2019 10:17 AM - edited 06-08-2019 10:21 AM
Technically you are most likely right. Defensive programming however says:
You shall not make assumptions!
It's currently the case that a LabVIEW node does not regenerate a refnum. But in the longer run there may be a chance, although fairly unlikely that LabVIEW may decide to to have to recreate a refnum for whatever reason.
More importantly though it is a not so uncommon case that you may end up at some time with code that explitly has to destroy an object and recreate it for whatever reason and if you or whoever will have to do that modification, forgets to change the tunnel to a shift register, the code will behave badly. By making it a shift register from the beginnning you avoid this potential pitfall in the future. This is defensive programming, by anticipating future modifications that may require additional functionality that does not cost you anything when implemented right from the beginning.
You are reusing the refnum yes and a shift register is very clear about what is actually happening. Everything else is assuming things, or as your second solution highly inefficient by recreating the object at every iteration.