HidLibrary
HidLibrary copied to clipboard
Leak of memory with "write"
Good day all, First, thanks Mike, for making available this library wich represents a really great work...
I am using a single "hiddevice.write" in a loop, and I found using the task manager of Windows that the memory used is increasing very fast... I have disabled all the calls to the library except one to be sure. Enabling and disabling this last call put in light the fact that it is the cause of the leak of memory.
here is the code of the loop: byte[] bufferout = new byte[9];
while (!aborting)
{
bufferout[0] = 0;
bufferout[1] = 2;
bufferout[3] = 3;
bufferout[2] = 0X41;
myDevice.Write(bufferout);
Thread.Sleep(10);
}
I am using Visual studio and C# under W7...
After some search in the source code, I found where is the problem:
public class HidDevices { private static Guid _hidClassGuid = Guid.Empty;
public static bool IsConnected(string devicePath)
{
//return EnumerateHidDevices().Where(x => x == devicePath).Any(); <===
return true;
}
Once the line put in comment and the return forced to true, no more leak...
By advance, thanks...
Robert
Robert,
Thanks for catching this! I just converted the source from VB.NET to C# and made some changes for x64 so I bet it has to do with that.
m
Hello all, 4 years after you I write a full HID program and a bit latte I found the same problem. I don't know how it could be solved? anyone? It looks like it is the only real C library working very nice and very simple today, it is very sad to have only that major bug! program stop working at 1.4GByte in memory :(
Hope someone could help. I'm an advanced beginner but that's all. Thanks
Hello @rapapar, Its been almost two years and I guess you've figured this out, but if not: I'd suggest pulling the sources from this GitHub repository, effecting the change suggested above then recompiling the VS solution to get the Hidlibrary assembly file (.dll). Then, reference the assembly in your own project and see if it solves your problem. Good luck.