Hello,
The following simple code leads to memory leak
IOHIDManagerRef hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDManagerOptionNone);
...
IOHIDManagerSetDeviceMatching(hidManager, matchingCriteria);
CFRelease(matchingCriteria);
if (IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) {
return 1;
}
...
if (IOHIDManagerClose(hidManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess)
{
return 1;
}
CFRelease(hidManager);
The following leaks report:
STACK OF 2 INSTANCES OF ROOT LEAK: <NSMutableArray>:
17 dyld 0x19b3aeb98 start + 6076
16 a.out 0x1027147e4 main + 200
15 com.apple.framework.IOKit 0x19f6781b8 __ApplyToDevices + 100
14 com.apple.CoreFoundation 0x19b801cfc CFSetApplyFunction + 224
13 com.apple.CoreFoundation 0x19b801dc0 CFBasicHashApply + 148
12 com.apple.CoreFoundation 0x19b801f94 __CFSetApplyFunction_block_invoke + 28
11 com.apple.framework.IOKit 0x19f6784c8 __IOHIDManagerDeviceApplier + 76
10 com.apple.framework.IOKit 0x19f5e18ec IOHIDDeviceOpen + 56
9 com.apple.iokit.IOHIDLib 0x102992cf0 0x102984000 + 60656
8 com.apple.iokit.IOHIDLib 0x10298d8ec 0x102984000 + 39148
7 com.apple.iokit.IOHIDLib 0x10298d3e8 0x102984000 + 37864
6 com.apple.framework.IOKit 0x19f5d5760 IORegistryEntrySearchCFProperty + 420
5 com.apple.framework.IOKit 0x19f5d66b4 IOCFUnserializeBinary + 480
4 com.apple.CoreFoundation 0x19b7d9ef0 __NSArrayM_new + 60
3 com.apple.CoreFoundation 0x19b7c2378 __CFAllocateObject + 20
2 libobjc.A.dylib 0x19b35b7ec class_createInstance + 76
1 libsystem_malloc.dylib 0x19b56ba40 _calloc + 88
0 libsystem_malloc.dylib 0x19b581270 _malloc_zone_calloc_instrumented_or_legacy + 132 _
I have not found any mention in documentation what should be released before/after the call IOHIDManagerClose.
Are there any advices?
Thank you in advance!
It seems very likely that this is just a bug in the IOHIDManager
, and I encourage you to file it as such. It’d be helpful if you could include a small test project that demonstrates the problems and attach a memory graph file.
Please post your bug number, just for the record.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"