简体   繁体   English

未分配的KVO发生奇怪的崩溃

[英]Weird crash on un-deallocated KVO

This has been dogging me for a while. 这一直困扰着我一段时间。

I have a NSOperation subclass running in an operation queue. 我在操作队列中运行了一个NSOperation子类。 I have had occasional, infrequent (but significant portions of our crashes) instances of crashes on what looks like a key-value observer. 我偶尔会在看起来像键值观察器的情况下发生崩溃,但是这种情况很少发生(但在崩溃中占很大一部分)。

The crash looks like 崩溃看起来像

Crashed: Thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x300000001099d05d
NSKeyValueDidChangeWithPerThreadPendingNotifications.llvm.93060043671412

[OperationClass markAsFinished]

...Which strongly implies an un-deregistered KVO object. ...强烈暗示未注销的KVO对象。 Problem is I can't find any references to KVO being added to this object. 问题是我找不到添加到该对象的对KVO的任何引用。 I've even gone to the trick of object swizzling to track calls to addObserver:forKeyPath:options:context: and there are no registrations to thse classes. 我什至使用了对象混淆的技巧来跟踪对addObserver:forKeyPath:options:context:的调用,并且这些类没有注册。

The only thing I can think of is something is implicitly registering a KVO, outside of the context of my source, but I don't know what would do this. 我唯一能想到的就是在源代码上下文之外隐式注册一个KVO,但是我不知道该怎么做。

Does anyone have any ideas? 有人有什么想法吗?

You haven't provided any code, so I can only talk in generalities, but if you look at the docs for NSOperation and NSOperationQueue , you'll see that they use KVC and KVO for monitoring dependencies, priorities, and execution states. 您没有提供任何代码,因此我只能概括地说,但是如果您查看NSOperationNSOperationQueue的文档,您会发现它们使用KVC和KVO监视依赖项,优先级和执行状态。 Based on the error statement, I'd say the code trying to send an 'Operation is Finished' notification that's being watched by KVO, and that's where things fall apart. 基于错误声明,我想说代码试图发送“操作已完成”通知,该通知正在被KVO监视,这就是问题的解决方法。 Maybe an operation is pulled off the queue and deallocated before the notification goes through? 也许在通知通过之前将操作从队列中拉出并重新分配? Maybe a queue is deallocating before one of its operations finishes? 也许队列在其中一个操作完成之前就正在分配内存? Maybe an operation is deallocating before one of its dependencies completes? 也许某个操作在其依赖项之一完成之前就正在取消分配? That's where I'd start looking, at any rate. 无论如何,这就是我开始寻找的地方。 Maybe put a breakpoint on the 'finished' property of NSOperation, see what comes up... 也许在NSOperation的“完成”属性上设置一个断点,看看会发生什么...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM