LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Free memory an external dll reserved

Hi everybody. I currently have a problem regarding memory used by a DLL.

I got a DLL from an external company wich i use to controll a Device. The DLL contains a function to initialise the connection to the device wich reserves about 3MB of memory space. But it reserves new 3MB Memory every time i call it again and has no function to free up this memory again. So i currently have a script wich calls this fuction and checks the return function to know if the device is connected to the PC. If it is, it gose on with its functions. But if it´s not i waits 50ms and repead so long, unit it the device is connected. So my VI reserves new 3MB of memory every 50ms if the device is not connected and crashes after a minute.

 

My question is: is there any way to free the memory reserved by the DLL again without changing the DLL? (as i said, it´s an external DLL and i don´t have any idear about modifying a DLL)

i tried to free the memory by wireing a empty path to the Call libary regarding this link of the knowledge base without success. http://digital.ni.com/public.nsf/allkb/77594203D78D12278625729100758BE5

 

Thanks for you help and greatings from Germany.

0 Kudos
Message 1 of 10
(3,377 Views)

Anyone got any idear? Is there a way to allocate a specific space of memory for the DLL and clear this specific space afterwards?

0 Kudos
Message 2 of 10
(3,320 Views)

The DLL would need to provide a way to release that memory. Otherwise, the operating system will hold on to it until your application exits, at which point it should clean up any resources such as memory that your program uses. Is there some other function provided in the DLL that will let you reuse the existing resources?

0 Kudos
Message 3 of 10
(3,306 Views)

Hello 

0 Kudos
Message 4 of 10
(3,288 Views)
LV has no control over the DLLso the only way for the system to know it's safe to release the memory is at program end. On the other hand, why do you need to initialize several times? Isn't it enough at program start, then release it at end(automatically)?
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 10
(3,281 Views)

Does the program need to be running during this query? I found that to release LabVIEW and the DLL was to create an external EXE that would load up the program (EXE) that you are using. So Program X(X) acting like a splash loads Program Y(Y) and Program Y is the one you would make the DLL call in. Usually once the DLL is unregistered (not being used anymore) windows will free up that memory space. Instead of making Y query the DLL until crash have  X continue to reload Y until your criteria is met. Its not a very good workaround, but it may work in your case. I do it because I have DLLs that conflict with each other and I use X to allow me to unload Y and free up the hardware DLL so that I don't crash the computer. Then on startup Y will load the different DLL I need, in my situation, corresponding to the slightly different piece of hardware installed.

0 Kudos
Message 6 of 10
(3,275 Views)

@CeeZero wrote:


I'm not sure that LabVIEW releases memory used by external resources when a VI stops running. Rather, the operating system releases all memory used by a program when the program stops running. The operating system can do this because each program is assigned its own memory space, isolated from other programs. This is a function of the operating system, not of LabVIEW. Until a program exits, the operating system has no way to know which resources (such as memory) are still in use by the application, so there cannot be an operating system command to clean up a program that's still running.

 

You could try setting up your Call Library Function Node with the path passed as a parameter. Passing an empty path to CLFN will unload the DLL, so if the DLL is written such that it cleans up its memory when it is unloaded, it could solve your problem. It will slow down your code to repeatedly load and unload the DLL, and it may not help.

 

As tmf171 suggests, you can also create a separate LabVIEW progam which you call through VI Server that handles all the calls to the DLL. I once did something similar. I had to use an external component that crashed frequently so I wrote a separate small application exclusively for that component. My main program launched it and connected to it through VI Server. If the application crashed, the VI Server connection failed and the main program restarted the external program. However, this approach runs more slowly and there's more development time required than simply calling a DLL in your main program.

0 Kudos
Message 7 of 10
(3,261 Views)

Thanks for all your replys.

@

0 Kudos
Message 8 of 10
(3,240 Views)

you need to setup the call library function node to specify path on diagram. Once the path is on diagram you wire the path into the call library function node. That is what nathand was trying to describe.

0 Kudos
Message 9 of 10
(3,231 Views)

Thanks again. I did this allready like descriped in the link of my first post.

 

 

0 Kudos
Message 10 of 10
(3,221 Views)