10-01-2011 07:07 AM
Hi, if I have a subVI containing a call library function that uses a dll, can I use "Request deallocation" to free space used by that dll after the subVI completed by itself?
Raymond
Solved! Go to Solution.
10-02-2011 08:52 AM
"Request deallocation" will not free any resources in use by the DLL.
Guenter
10-03-2011 01:26 PM
Where in your code are you trying to deallocate memory? Is it in the top level VI or in a subVI? If memory is deallocated at all depends on your subvi and if it stopped executing.
10-03-2011 06:14 PM
Hi It's in my subVI. That subVI keep start running and finish running all the time. Would indeed the dll in that subVI would release its memory once that subVI finishes running without using a "Request deallocate"?
10-04-2011 12:08 PM
"When the subVI finishes running, LabVIEW usually does not deallocate the data space until the top-level VI finishes running or until the entire application stops." -LabVIEW Help
When placed in a sub VI Request Deallocation only frees up temporary memory used by VIs in memory in the non-run state.
Temporary memory are any copies of data that LabVIEW makes during execution that never needs to be stored in a VI to be preserved between calls. For example, a branched wire creates a copy of data, if that data is a large array and one branch goes to "index array" and the other goes to "replace array subset", the copy made for index array is temporary. Data that is connected to controls, indicators, uninitialized shift registers, etc... are not temporary as there are situations in which they will need to be 'remembered' by the VI for subsiquent runs. This data is not freed.
VIs that are called dynamically and properly unloaded always clear the entire dataspace of that sub VI.
Therefore, I suggest that you use dynamically launched VI's to completely release the entire VI memory space when a VI is called. This would involve using an Open VI Reference function to load the VI into memory, a Run VI method, and a Close Reference function to call a subVI, rather than a statically linked subVI. This way the VI leaves memory completely when the Close Reference is called, saving space for any subsequent calls to other memory intensive subVIs.
Note: Calling request deallocation in a sub-VI that is loaded and unloaded dynamically will have absolutely no effect on memory since the entire dataspace is cleared anyway.
10-04-2011 09:40 PM
Hi Sev,
Then back to my orginial concern, would doing opening and closing VI dynamically clear resources that was once used by a Dll in that VI? Is a dynamically opened VI a top-level VI?
Raymond
10-05-2011 12:05 PM
In the "Call Library Function" in your subVI code go to "Functions" tab. Set the "Thread" to "Run in UI Thread". Once you close the reference to the subVI in the top level VI it should clear all the memory used by the DLLs if they were executed in the UI thread.
10-05-2011 04:35 PM
@Sev K wrote:
In the "Call Library Function" in your subVI code go to "Functions" tab. Set the "Thread" to "Run in UI Thread". Once you close the reference to the subVI in the top level VI it should clear all the memory used by the DLLs if they were executed in the UI thread.
Hi all.
I was thinking of a DLL that is still holding a resource (e.g. an open file or some allocated memory) which would be transparent to "Call Library Function Node". Thus, unloading the VI (and the DLL) should result in "freed resources... As long as the DLL's code does not need to keep any data between calls, this technique should be exactly what you want.
I am wondering if it is required to configure the Call Library Function Node to run in the UI Thread: Until now I have preferred to make calls to a DLL reentrant and - if desired - configure the VI Properties of the calling VI to "non reentrant". Is there a need to use the UI Thread?
Regards, Guenter
10-06-2011
10:54 AM
- last edited on
04-18-2025
03:46 PM
by
Content Cleaner
Hi Guenter,
It would make sense to configure the "Call Library Function" to run in UI thread if you are conserned about the memory space used by the VI and want to make sure this space is deallocated when the VI stops running.
Reentrant execution realtes more to the way the subVI is being used by other VIs. If the subVI is set to "Reentrant execution" than it can be called by more than one caller simultaneously. Under the "Reentrant execution" you can also select the way you want the memory to be allocated when the subVI is called (Share clones between instances or Preallocate clone for each instance). (https://www.ni.com/docs/en-US/bundle/labview/page/suggestions-for-using-execution-systems-and-priori...). You can still configure the "Call Library Function" of a reentrant subVI to run in UI thread if you want to make sure the memory gets deallocated when the VI stops running. However, make sure that the subVI is being called dynamically as discussed above.