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:
from DebugDiag 1.2:
Allocation type Heap allocation(s)
Heap handle 0xdf55fa50
Allocation Count 49104 allocation(s)
Allocation Size 3.89 MBytes
Leak Probability 100%
Call stack sample 1
Code: Select all
Address 0x00000005 Allocation Time 00:05:10 since tracking started Allocation Size 83 Bytes [b]Function Source Destination [/b] usbtc08+31ea kernel32!LocalAllocStub ntdll!ZwWaitForMultipleObjects+15 KERNELBASE!WaitForMultipleObjectsEx+100 ntdll!ZwWaitForMultipleObjects ntdll!NtReleaseMutant+15 KERNELBASE!ReleaseMutex+10 ntdll!NtReleaseMutant KERNELBASE!_except_handler4 KERNELBASE!_except_handler4 ntdll!_except_handler4 usbtc08!usb_tc08_open_unit_async+115e1 clr!StubHelpers::DemandPermission+6e 0xF9D6AD2 0xF9D6AD2 ntdll!KiUserCallbackExceptionHandler user32!_except_handler4 user32!_except_handler4 ntdll!_except_handler4 lvrt!PNGToLVImageDataPreflight+5ec50 lvrt!PNGToLVImageDataPreflight+5ec50
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 . . . .
please help . . . .