soffes / HotKey

Simple global shortcuts in macOS
MIT License
921 stars 82 forks source link

Memory Leak from KeyCombo Dictionary Extension #18

Open ajkendall opened 4 years ago

ajkendall commented 4 years ago

I am getting a memory leak using instruments that goes away as soon as I comment out the KeyCombo dictionary extension... below is the code I am using - any chance you can take a look?

deployment target: 10.15 xcode version: 11.2

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    var myHotkey: HotKey? {
        didSet {
            guard let myHotkey = myHotkey else { return }
            myHotkey.keyDownHandler = { [weak self] in
                self?.hotkeyHandler()
            }
        }
    }

    var num: Int = 0

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        self.myHotkey = HotKey(carbonKeyCode: UInt32(47), carbonModifiers: UInt32(2304))
    }

    func hotkeyHandler() {
        self.num += 1
        print("hotkey pressed \(num) times")

    }
}