Call viClose()
This is the NI-VISA termination routine, which must be included at the end (or abort) of any application. You should call viClose() on any instrument handles that you have opened once you are done accessing that instrument. Calling viClose() on the Resource Manager handle disables interrupts and frees dynamic memory allocated for the internal Resource Manager table and other structures. Although you attempt to perform clean-up operations, failure to call viClose() on the Resource Manager handle when terminating your application can cause unpredictable and undesirable results. If your application can be aborted from some operating system abort routine, be certain to install an abort/close routine that calls viClose() on outstanding handles.