【问题标题】:How to view and debug active key value observers如何查看和调试活动键值观察者
【发布时间】:2014-10-03 16:46:16
【问题描述】:
  1. 典型故事...从一年前离职的程序员那里继承了一个有缺陷的应用程序。
  2. 应用使用了一些时髦的过渡插件;即 iCarousel、MPFFlipTransition。
  3. 应用会弹出单独的浏览器标签。
  4. 关闭浏览器或浏览器选项卡时引发错误
  5. 观察者在某处被泄露。
  6. 我已将以下代码添加到相关类中,但没有成功:

    • (无效)dealloc { //实现dealloc方法/删除 [[NSNotificationCenter defaultCenter] removeObserver:self]; }

如何跟踪应用程序以找到设置此观察者的位置?我可以观察特定的内存位置吗?我可以以某种方式查看键/值对吗?谢谢,基思

抛出错误:

2014-10-03 12:33:20.938 myApp[5299:60b] An instance 0x145661f0 of class DesktopBrowserVC was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
<NSKeyValueObservationInfo 0x14547300> (
<NSKeyValueObservance 0x14547210: Observer: 0x145550a0, Key path: title, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x14547320>

【问题讨论】:

  • KVO 与 NSNotificationCenter 是分开的。您是否在代码中看到添加了 KVO 观察者但没有后续 removeObserver 调用(在 dealloc 或诸如此类)的任何地方?

标签: ios xcode key-value key-value-observing dealloc


【解决方案1】:

您可以通过搜索项目 (Cmd+Shift+F) 轻松找到为该关键路径添加任何观察者的位置字符串forKeyPath:@"title"

您还可以通过调用以下方法随时调查当前正在观察您的任何对象的观察者:

[NSObject observationInfo]

正如@AaronWojnowski 所说,确保您没有将键值观察者与 NSNotificationCenter 观察者混淆!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多