When I hit the hot keys composed of ⌃⌘Space (a system-wide shortcut), isTakenError: method will early return (excute return YES; )
BUT on return, globalHotKeys still not be released, we have not an opportunity to release the globalHotKeys:
So I wonder that is this a potential memory leak? ( Please see the comment above return YES; )
- (BOOL)isTakenError:(NSError **)outError
{
CFArrayRef globalHotKeys;
if (CopySymbolicHotKeys(&globalHotKeys) == noErr) {
// Enumerate all global hotkeys and check if any of them matches current shortcut
for (CFIndex i = 0, count = CFArrayGetCount(globalHotKeys); i < count; i++) {
CFDictionaryRef hotKeyInfo = CFArrayGetValueAtIndex(globalHotKeys, i);
CFNumberRef code = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyCode);
CFNumberRef flags = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyModifiers);
CFNumberRef enabled = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyEnabled);
if (([(__bridge NSNumber *)code unsignedIntegerValue] == self.keyCode) &&
([(__bridge NSNumber *)flags unsignedIntegerValue] == self.carbonFlags) &&
([(__bridge NSNumber *)enabled boolValue])) {
if (outError) {
NSString *description = NSLocalizedString(@"This combination cannot be used because it is already used by a system-wide "
@"keyboard shortcut.\nIf you really want to use this key combination, most shortcuts "
@"can be changed in the Keyboard & Mouse panel in System Preferences.",
@"Message for alert when shortcut is already used by the system");
NSDictionary *info = [NSDictionary dictionaryWithObject:description forKey:NSLocalizedDescriptionKey];
*outError = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:info];
}
/* On return, globalHotKeys still not be released, is this a potential memory leak?
* Perhaps there should be a CFRelease( globalHotKeys );
*/
return YES;
}
}
CFRelease(globalHotKeys);
}
return [self isKeyEquivalent:self.keyCodeStringForKeyEquivalent flags:self.modifierFlags takenInMenu:[NSApp mainMenu] error:outError];
}
When I hit the hot keys composed of
⌃⌘Space
(a system-wide shortcut),isTakenError:
method will early return (excute return YES; )BUT on return, globalHotKeys still not be released, we have not an opportunity to release the globalHotKeys:
So I wonder that is this a potential memory leak? ( Please see the comment above
return YES;
)