Test and Measurement Forum

TC-08 .dll memory leak when called from .NET static library

Post any questions you may have about our current range of USB data loggers

TC-08 .dll memory leak when called from .NET static library

Postby jerzydziewierz » Thu May 08, 2014 7:56 pm

Hello,

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:

Function usbtc08+31ea
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 . . . .
jerzydziewierz
Newbie
 
Posts: 0
Joined: Thu May 08, 2014 7:27 pm

Re: TC-08 .dll memory leak when called from .NET static libr

Postby Karunen » Fri May 16, 2014 10:44 am

Hi,

Could you please send the full memory analysis to support@picotech.com?

If you don't mind could you also do a memory analysis of the SDK example just because it give me a place to start looking into this.

Thanks,
Karunen

Technical Specialist
Pico Technology
Karunen
Zen Master
Zen Master
 
Posts: 194
Joined: Thu Nov 21, 2013 9:22 am

Re: TC-08 .dll memory leak when called from .NET static libr

Postby jerzydziewierz » Sun May 18, 2014 1:51 pm

Hi,

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.

Good luck,

Jerzy Dziewierz
jerzydziewierz
Newbie
 
Posts: 0
Joined: Thu May 08, 2014 7:27 pm

Re: TC-08 .dll memory leak when called from .NET static libr

Postby Karunen » Tue May 27, 2014 2:27 pm

Hi,

Thank you for all the information I will pass it over to the development team so they can have a look at it.

Thanks,
Karunen

Technical Specialist
Pico Technology
Karunen
Zen Master
Zen Master
 
Posts: 194
Joined: Thu Nov 21, 2013 9:22 am


Return to USB PC Data Loggers

Who is online

Users browsing this forum: No registered users and 0 guests