G#

cancel
Showing results for 
Search instead for 
Did you mean: 

Generic Create Question

The generic create method included in the G# library has a "keep constructor vi ref open" option which is defaulted to True.  I'm running into a situation where I'd like to use the generic create method to create an object at one point in the program and again to "load" the object at another point in the program.  I've found that I am able to achieve this by changing this option to False but I'm worried there may be consequences.  Is there any reason to keep this reference loaded into the program?

Thanks,

Randy

0 Kudos
Message 1 of 2
(4,171 Views)

Hi,

The only purpose of "keep constructor vi ref open" is to prevent LabVIEW from unloading the VI from memory. Typically you would like the VI to remain in memory until the application is finsihed, but if you need to get the VI out of memory, the best way is to set the option to false.

However, there is one major drawback by using the "G#Object_GenericCreate.vi" and that is that the VI will execute as a top-level VI and not as a sub VI. The consequence of this is that any resource like queues, tcpip connections. etc that you might create inside your constructor will be garbage collected by LabVIEWs internal garbage management immediately when your create VI finish executing. The way to get around this problem and the way that we recommend (and always do at AddQ) is to used the "G#Object_GenericDefaultContructor.vi" instead. This will require that you implement and override the "G#Object_Create.vi" and inside this VI places you ordinary constructor. This "G#Object_Create.vi" has an array of variants that you can map your constructor parameters to (this array is an input to the G#Object_GenericDefaultConstructor.vi). When doing this way, your constructor will be executed by LabVIEW as a "true" subVI and all problems with LabVIEWs internal garbage collector will be gone. Please notice that it is not possible to unload the contructor (as it is with the G#Object_GenericCreate.vi).

There is an example project called "G# - Depedency Injections.lvproj" shiped with G#Framework. Just search for "G#" in the LabVIEW examples. There is also a third example of how to use the "External Create Process" together with "G#Object_GenericDefaultConstructor.vi" that addresses the problem using multiple top level VIs. LabVIEW will automatically garbage collect all queues and DVRs (and thereby all G#Objects) when the top-level VI "owning" them will stop execute. By using the "External Create Process", G# will delegate the creation of the objects to the external create background process and objects will therefore not be destroyed util the last toplevel VI will stop. In the G#Debugger there is a field indicating with top-level VI that "owns" the object. There was another discussion regarding this issue on there G# forum a few months ago.

Thanks,

Mattias

0 Kudos
Message 2 of 2
(3,322 Views)