The following section describes the standard case in which you have a code resource referenced by only one CIN and the VI containing the CIN is not reentrant. Other cases, such as when you have a code resource loaded into multiple CINs or have multiple references to the same CIN in different VIs, have slightly more complicated behavior.
When you first load a VI, LabVIEW calls the CINLoad routines for any CINs contained in that VI. By LabVIEW calling the CINLoad routines when you first load a VI, you have a chance to load any file-based resources at load time because LabVIEW calls this routine only when the VI is first loaded. However, there are some exceptions to this rule. After LabVIEW calls the CINLoad routine, it calls CINInit. Together, CINLoad and CINInit perform any initialization you need before the VI runs.
LabVIEW calls CINLoad once for a given code resource, regardless of the number of data spaces and the number of references to that code resource. Because LabVIEW calls CINLoad once for a given code resource, you should initialize code globals in CINLoad.
LabVIEW calls CINInit for a given code resource a total of one time for each CIN data space multiplied by the number of references to the code resource in the VI corresponding to that data space. If you want to use CIN data space globals, initialize them in CINInit.
When you close a VI front panel, LabVIEW checks whether any references to the VI are in memory. If any references to the VI are in memory, the VI code and data space remain in memory. When all references to a VI are removed from memory and its front panel is not open, the VI is unloaded from memory.
When a VI is unloaded from memory, LabVIEW calls the CINDispose routine, giving you a chance to dispose of anything you allocated earlier. CINDispose is called for each CINInit call. For example, if you used NewHandle in your CINInit routine, you should use DisposeHandle in your CINDispose routine. LabVIEW calls CINDispose for a code resource once for each individual CIN data space.
As the last reference to the code resource is removed from memory, LabVIEW calls the CINUnload routine for that code resource once, giving you the chance to dispose of anything allocated in CINLoad. As with CINDispose and CINInit, CINUnload is called for each CINLoad. For example, if you loaded some resources from a file in CINLoad, you can free the memory those resources are using in CINUnload. After LabVIEW calls CINUnload, the code resource itself is unloaded from memory.
If you load a new code resource into a CIN, the old code resource is first given a chance to dispose of anything it needs to dispose. LabVIEW calls CINDispose for each CIN data space and each reference to the code resource, followed by the CINUnload for the old resource.
After the calls to CINDispose and CINUnload, the new code resource is given a chance to perform any initialization it needs to perform. LabVIEW calls CINLoad for the new code resource. After LabVIEW calls CINLoad, it calls the CINInit routine once for each data space and each reference to the code resource.
When you compile a VI, LabVIEW recreates the VI data space, including resetting all uninitialized shift registers to their default values. Also, your CIN is given a chance to dispose or initialize any storage it manages.
LabVIEW completes the following steps when compiling a VI and before disposing of the current data space:
Click the Run button in a VI to run the VI. When LabVIEW encounters a Code Interface Node, it calls the CINRun routine for that node.
When you save a VI, LabVIEW calls the CINSave routine for that VI. Calling the CINSave routine gives you the chance to save any resources, such as something you loaded in CINLoad. When you save a VI, LabVIEW creates a new version of the file, even if you are saving the VI with the same name. If the save is successful, LabVIEW deletes the old file and renames the new file with the original name. Therefore, you need to save in CINSave anything you expect to be able to load in CINLoad.
When you abort a VI, LabVIEW calls the CINAbort routine for every reference to a code resource contained in the VI being aborted. LabVIEW also calls the CINAbort routine of all actively running subVIs. If a CIN is in a reentrant VI, CINAbort is called for each CIN data space, as well. CINs in VIs not currently running are not notified by LabVIEW of the abort event.
CINAbort only works if the VI containing the CIN is running. If a top level VI is running and the program is aborted, CINAbort only works if the top level VI is currently running the subVI in which the CIN is located. If the top level VI is running another subVI in the hierarchy, CINAbort does not work.
CINs are synchronous. Therefore, when a CIN begins execution, the CIN takes control of its thread until execution is completed.