核心数据+ NS操作队列
我有一个 NSOperation 的子类,它的属性之一是 ManagedObject。 我需要将多个操作添加到 nsoperationqueue &观察他们的完成情况。 对于每个 NSOperation 实例,我创建了一个新的托管对象,如 Apple 文档所述“为每个线程创建单独的托管对象上下文并共享单个持久存储协调器。”。 第一次操作完成后,我会收到以下崩溃日志。
#0 0x34970c98 in objc_msgSend ()
#1 0x3608704e in -[_PFArray dealloc] ()
#2 0x36084b80 in -[_PFArray release] ()
#3 0x3179b1a0 in CFRelease ()
#4 0x3179deba in _CFAutoreleasePoolPop ()
#5 0x30d7bbb4 in NSPopAutoreleasePool ()
#6 0x30d91e1c in -[__NSOperationInternal start] ()
#7 0x30d91a7e in -[NSOperation start] ()
#8 0x30df7eca in ____startOperations_block_invoke_2 ()
#9 0x33a248e6 in _dispatch_call_block_and_release ()
#10 0x33a1a532 in _dispatch_worker_thread2 ()
#11 0x368bf590 in _pthread_wqthread ()
#12 0x368bfbc4 in start_wqthread ()
从日志中看来,某些对象正在过度释放。我如何才能获取哪个对象正在过度释放? 应用程序在 NSZombieEnabled 下运行,但仅收到上述信息。 NsOperation 是否维护自己的自动释放池?
i have a subclass of NSOperation which have managedObject as one of its property.
I need to add multiple operation to nsoperationqueue & observe their finish.
For each NSOperation instance i created a new managed object as Apple documentation state "Create a separate managed object context for each thread and share a single persistent store coordinator.".
Once the first operation is finished i get following crash log
#0 0x34970c98 in objc_msgSend ()
#1 0x3608704e in -[_PFArray dealloc] ()
#2 0x36084b80 in -[_PFArray release] ()
#3 0x3179b1a0 in CFRelease ()
#4 0x3179deba in _CFAutoreleasePoolPop ()
#5 0x30d7bbb4 in NSPopAutoreleasePool ()
#6 0x30d91e1c in -[__NSOperationInternal start] ()
#7 0x30d91a7e in -[NSOperation start] ()
#8 0x30df7eca in ____startOperations_block_invoke_2 ()
#9 0x33a248e6 in _dispatch_call_block_and_release ()
#10 0x33a1a532 in _dispatch_worker_thread2 ()
#11 0x368bf590 in _pthread_wqthread ()
#12 0x368bfbc4 in start_wqthread ()
From logs it seems some object is getting over-release.How i can get which object is over-release?
App is run with NSZombieEnabled but only above info is received.
do the NsOperation maintain its own autorelease pool?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是您的线索:
这是您在操作中释放的东西。
它是一个自动释放的对象。这并不一定意味着您已经编写了 autorelease 方法调用。通过 [NSString stringWithFormat:...] 等便捷方法创建的对象在返回之前会自动释放。因此,请在操作代码中查找调用 autorelease 的位置,或者在不使用 alloc-init 模式的情况下创建对象的位置。
是的,NSOperation 维护自己的自动释放池。你不必担心这一点。如果您仅在使用完对象时释放对象,并且仅在方法作用域结束时使用它们时自动释放对象(或者如果返回它们则调用方法作用域),那么应该没问题。
它是存储在被过度释放的数组(而不是数组本身)中的对象。
此类错误意味着您在不应该释放或自动释放对象的情况下释放或自动释放了对象,或者在应该保留对象时没有保留对象。它可能是不正确的释放或不正确的自动释放,即使错误发生在自动释放池中。自动释放可能是正确的,而释放也可能是不正确的。无论哪种方式,当自动释放池耗尽时都会发生错误,因为这会在稍后发生。
Here are your clues:
It is something you are releasing in your operation.
It is an object that is autoreleased. That does not necessarily mean you have written the autorelease method call. Objects that are created by convenience methods like [NSString stringWithFormat:...] are autoreleased before they are returned. So look for either a place in your operation code where you are calling autorelease or a place where you are creating an object without the alloc-init pattern.
Yes, an NSOperation maintains its own autorelease pool. You shouldn't have to worry about that. If you only release objects when you are done with them, and only autorelease objects when you will be done with them by the end of the method scope (or calling method scope if returning them) you should be fine.
It is an object stored in an array (not the array itself) that is being overreleased.
An error of that kind means you are either releasing or autoreleasing an object when you shouldn't, or you are not retaining an object when you should. It could be either an incorrect release or an incorrect autorelease, even though the error occurs with the autorelease pool. The autorelease could be correct and the release could be incorrect. Either way the error will happen when the autorelease pool is drained because that happens later.