I am developing an OPC server for multiple USB TC-08 thermocouple data loggers.
I have a memory leak somewhere and after extensive debugging, it appears to me that usbtc08.dll at usbtc08+31ea is allocating and never releasing memory. With two TC-08 units connected, it allocated and not released 3.94MB of memory in my debug run of 40 minutes.
I am using usb_tc08_get_single() for each unit once per 10 seconds. I am also calling usb_tc08_open_unit() each loop to check for disconnected/ re-connected devices (we intend to have some 10 of them in a single experiment, so i am planning for hardware failures).
I am using the code exactly like in the SDK c-sharp example code - TC08Imports:
float[] tempbuffer = new float[PicoThermocouplesPerDevice];
short status = Imports.TC08GetSingle(DeviceHandle, tempbuffer,&overflow, Imports.TempUnit.USBTC08_UNITS_CENTIGRADE);
if (status == 1)
{
// read OK. Write to the buffer
for (int ThermoCoupleIdx = 0; ThermoCoupleIdx < tempbuffer.Length; ThermoCoupleIdx++)
{
Program.TempReadings[ChannelIdx, ThermoCoupleIdx] = tempbuffer[ThermoCoupleIdx];
}// end read temp buffer
} // end if read OK
note that this is c-sharp code and i have verified that tempbuffer is properly released by the garbage collector.
unfortunately i cannot attach the full memory analysis report because it is more than 256kb, but a relevant part of it says:
I also note that in 7 out of 7 call stack examples, there is usbtc08!usb_tc08_open_unit_async+(XXX) present where XXX varies, and it's location in the stack also varies.
At this rate, the app leaks approximately 16 MB per hour and blocks the computer in approx. 4 days of continuous use, which is way to short for our application . . . .
altough i cannot send the report just now, i have found that there is virtually no leak (or at most, a very small one) when just acquiring the data. THe problem was that I was trying to compensate for disconnected/reconnected devices in our system (we have 6 dataloggers in current experiment, might be more later on) by detecting new devices every 10 seconds.
I have disabled that part of the code and the leak went away. In my code, now it will only look for new devices when requested by user.
So the SDK example will not *leak* memory in a noticeable way, because it only detects devices once. You will have to modify it to continiously look for new devices to see the leak.