LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview unload dll empty path

In Labivew 8.2 Help, under "Call Library Function Dialog Box," it has the following tip listed:

" You can use the reference in input to unload a previously referenced library from memory. Wire an empty or invalid path to the reference in input to unload any library previously referenced by the node from memory"

Has anyone successfully done this before? 

My application:  I am writing a VI to operate a pulser/receiver through USB.  Its functions are accessible through a dll written by the manufacturer.  I am thinking that I may improve the behavior of my program if I can unload the dll at the end.  I have tried wiring an empty path by using the "build path" icon with an empty string wired in, and I have the build path icon wired into the "reference in" input to the call library function  node.  I don't think this works, but I wanted to see if anyone has done it before.  Can I see an example?
0 Kudos
Message 1 of 4
(4,219 Views)
Hi Amaunette,

It appears that the DLL is going to stay in memory by default as long as your VI or EXE that references it is in memory. I recommend that you download some sort of a process viewer to see when it is in memory or not.

Are you concerned with the size in memory that this DLL takes up, or why are you looking into this? I'm not sure how this would improve the behavior of your program.

I am going to need to look into how exactly it is "unloaded", since for me, even after wiring an empty reference in to it, the dll was still visible with my process viewer.

Kind regards,
-Sam F, DAQ Marketing Manager
0 Kudos
Message 2 of 4
(4,197 Views)

I have tried out to check if the loading and unloading of DLL works in LabVIEW. I see that it does, and there are examples in the web for very simple case, like for e.g. when using a single Call Library Function (CLF) node. However, when there are multiple CLFs, things are not as easy as it seems.

 

Things that you must keep in mind is that the loading of DLL takes place with the first CLF, which also saves a reference to the DLL. Subsequent CLFs must have their path-in connected to the path-out of the previous CLF. This way it works as when unloading, the empty path will also be relayed from the first CLF to the subsequent CLFs.

 

However, I have tested to check if it works when the CLFs are within the Case structures. I found that it does not. This is because some of the references to the DLLs are still active which are not released when specific true/false case block is executed. 

 

On the event that you can free all the references to the DLL, it gets unloaded, but missing a single reference would mean it would not be unloaded at all.

If anyone knows the way to release all the references to the DLL, it would be great to check if would work for Case structures.

 

- Ramesh Marikhu

0 Kudos
Message 3 of 4
(3,874 Views)

 


@marikhu wrote:

On the event that you can free all the references to the DLL, it gets unloaded, but missing a single reference would mean it would not be unloaded at all.

If anyone knows the way to release all the references to the DLL, it would be great to check if would work for Case structures.

 

- Ramesh Marikhu


 

There isn't, other than making sure every Call Library Node that has loaded the DLL is also called with an empty path. Windows and most other dynamic library implementations (I knowHP-UNIX used to not do that at least in early versions) maintain a reference count for each DLL which is incremented with every call to LoadLibrary() or equivalent and decremented on FreeLibrary(). The OS only unloads a DLL when its reference count reaches 0.

 

A Call Library Node calls LoadLibrary() whenever it receives a non empty path on it's input that is not equivalent to the previous path. It calls FreeLibrary() on the previous DLL path when a different or empty path is passed to it.

 

When the path input to the Call Library Node is not enabled then LoadLibrary() is called for each such CLN on the configured library path when the VI gets loaded and FreeLibrary() when the VI is unloaded.

 

 

badmaster4 good: this one he agree to come with me
badmaster4 good: this one not happy to come
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 4 of 4
(3,854 Views)