Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx memory leak in C++

Hi

 

I am facing memory leak issue with DAQmx in my application. To verify I compiled and ran an exampleprovided with NI-DAQmx installation.

"National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Acq-Ext Clk"

 

When I ran the application memory shoots from 9704K to  18,116K and I waited for a long time before I press a key to exit the application, but the memory usage didnt came down.

 

Why is it so? The sample application is using StopTask() and ClearTask() but the memory alloted for the task (by daqmx) is not getting released! Is this a bug in DAQmx?

 

regards

Praveen.DA

 

0 Kudos
Message 1 of 2
(2,885 Views)

Praveen da,

You will see memory leaks in any user programs that use the Read...Async or Write...Async methods of the C++ DAQmx API. This is not a bug. These leaks are reported because the DAQmx C++ API creates additional threads to support asynchronous operations and, when exiting, in some cases the process will terminate before the threads have a chance to release all of the memory they are using. This only can occur when the process is ending. The memory will be released by Windows process termination. Put a Sleep(100) call in your program after uninstalling your event handlers and deleting your reader or writer object and CNiDAQmxTask object. This will give the asynchronous threads an opportunity to clean up before your application's process terminates. This is not necessary for correct functioning of the program, however.

0 Kudos
Message 2 of 2
(2,865 Views)