问候:仪器告诉我,我在viewDidLoad中的两个viewDidLoad调用中有内存泄漏(每片3字节)。我很高兴有人告诉我我的错误和这可能是泄漏的原因。任何帮助都是非常感谢的!
环境:
代码
override func keyDown(with theEvent: NSEvent) {
nextResponder?.keyDown(with: theEvent)
let hasCommand = theEvent.modifierFlags.contains(.command)
switch theEvent.charactersIgnoringModifiers! {
case "q" where hasCommand == true: // Capture "Command-Q"
let app = NSApplication.shared
app.terminate(NSApplication.shared.delegate as! AppDelegate)
break
default:
break
}
}
override func viewDidLoad() {
super.viewDidLoad()
NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [unowned self] (theEvent) -> NSEvent? in
self.keyDown(with: theEvent)
return theEvent
}
NSEvent.addLocalMonitorForEvents(matching: .flagsChanged) { [unowned self] (theEvent) -> NSEvent? in
self.flagsChanged(with: theEvent)
return theEvent
}
}发布于 2018-06-10 14:58:14
对于任何一个偶然发现这个问题的人来说,就像往常一样--呈现漏洞通常是其他地方的症状。原来我错过了一个被埋葬在别处的封闭中的自我。一旦补救,这个“泄漏”就消失了。针头碰头干草堆。
底线:上面的语法不是错误的.
https://stackoverflow.com/questions/50775982
复制相似问题