LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Request deallocation

Solved!
Go to solution

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

0 Kudos
Message 1 of 9
(3,589 Views)
Solution
Accepted by topic author vgbraymond

"Request deallocation" will not free any resources in use by the DLL.

Guenter

0 Kudos
Message 2 of 9
(3,561 Views)

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.

Sev K.
Senior Systems R&D Engineer | Wireless | CLA
National Instruments
0 Kudos
Message 3 of 9
(3,530 Views)

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"?

0 Kudos
Message 4 of 9
(3,522 Views)

"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.

 

Sev K.
Senior Systems R&D Engineer | Wireless | CLA
National Instruments
Message 5 of 9
(3,494 Views)

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

0 Kudos
Message 6 of 9
(3,475 Views)

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.

Sev K.
Senior Systems R&D Engineer | Wireless | CLA
National Instruments
Message 7 of 9
(3,458 Views)

@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

0 Kudos
Message 8 of 9
(3,445 Views)

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.

Sev K.
Senior Systems R&D Engineer | Wireless | CLA
National Instruments
Message 9 of 9
(3,431 Views)