08-17-2021 03:43 PM
I am working on a LabVIEW Driver that will be used by a Test Stand developer. I have created a Constructor VI and the "command" or "do" VIs. What I do not have is a Destructor VI.
Do I need one? I guess is really the first question. It seems to me I do. We have them for queues, etc.
I like how Ben shows what is needed with his icon in this thread.
Ideas to release the memory associated with Dynamically Instanciated Objects - NI Community
My question is: What is Best Practice for delivering a Destroy VI to a TS Developer?
Secondary question: A close VI can be used that defaults all class items. But should there not also be a Destroy VI?
08-17-2021 04:13 PM
You really only need a destructor if the class opens any references that you would want closed but I don't think it's a terrible idea to have one anyway.
If you're only using by-value data (ints, strings, bools, etc.) then there you wouldn't need a constructor (for example you don't need any destructor or close function for an error cluster). However, if you don't have a close method in the parent class that defines the API then you are likely to run into issues if a child opens up some reference that you need to close.
08-19-2021 09:29 AM
In my class I do have a reference to a TCP/IP Connection ID.
As in the example image I sent, my "Constructor" is an Object constant that I encapsulate in a subVI.
My "Destructor" is just a subVI with the class object wire going into it but not out of it. This can help the readability of the program as it can be seen by the programmer that the wire stops. Seems like there should be a better way.
08-19-2021 09:39 AM
Since LVOOP is "Clusters with functions" and works by value, you don't need a constructor or destructor. Much like with Clusters. LV's memory management handles that. It's created at first function and destroyed when not referenced. (basically)
08-25-2021 05:02 PM - edited 08-25-2021 05:02 PM
It makes sense what you are saying.
I am going to make a destroy VI that basically has the Object wire going into it and not coming out. This will give the user of the code the visual clue that the wire is no longer to be used.
Thanks for your reply.
08-26-2021 03:12 AM
Just a note: If you create references or such that's stored in the object, they might need handling ...