HidLibrary
HidLibrary copied to clipboard
HidDevices.EnumerateHidDevices memory leak due to yield
Running on both XP (32bit) and Windows 7 (64bit) with the Logitech G13 controller - I've noticed severe memory leaking and it appears to be caused by using the yield keyword at line 69, preventing NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet) at line 72 from ever being reached. This can be fixed by removing the yield statement, moving var devices = new List
Thanks for the great work!
im not sure thats the right way to fix... this to me is the right way... line 69 onward: //yield return devicePath; } } NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet);
foreach (string devicePath in devices) { yield return devicePath; }
}
so that it builds the list of devicepaths... then yield a devicepath for each literation though the IEnumerable and this allows you to stop your illertation at any point, and not have deviceInfoSet left in memory
devices is already an IEnumerable
true, i guess, but then we cant use the cool YIELD statement :)
Thank you so much, this cured my memory leak!
Worked for me also. Thanks!
Can someone make a pull request for this and possibly unit tests?