I developed system using PIC18F26J50. I wrote a PC program using the Microchip “Generic HID - HID DLL Library” for communication . I am continuously reading the byte data using USBREADREPORT mehods. The program works for ~2 hours and then the performance degrades. I was looking with Windows Task Manager and observed that the Handle count increased continuously and increases in time. This indicates a memory leak. I thought that I have a mistake in my program but I insolated the problem and fond the memory leak in the HID class.dll.
Is there any solution that solved this problem?
Thanks in advance for any help.
while (true)
{
lock (this)
{
unsafe
{
if ((PerformUsBdataRead()) && (InputPacketBuffer[0] != Nodata))
{
//handle stylus events same as mouse events
}
}
}
}
//USB Read data
private static bool PerformUsBdataRead()
{
unsafe
{
IntPtr unmanagedPointer = Marshal.AllocHGlobal(65);
InputPacketBuffer[0] = 0;
byte* inputPacketBufferPointer = (byte*)unmanagedPointer.ToPointer();
if (HIDClass.MCHPHIDClass.USBHIDReadReport(inputPacketBufferPointer))
{
unmanagedPointer = (IntPtr)inputPacketBufferPointer;
Marshal.Copy(unmanagedPointer, InputPacketBuffer, 0, 65);
Marshal.FreeHGlobal(unmanagedPointer);
return true;
}
else
{
Marshal.FreeHGlobal(unmanagedPointer);
return false;
}
}
}