理解 NSZombie 日志
我正在尝试跟踪 ex-bad-access。我已经在启用 NSZombie 的情况下运行 Instruments,当应用程序崩溃时,我收到此错误日志。有一个 UIView 自动释放了四次,但在自动释放池耗尽之前,它的引用计数仅为 3,因此 int 以 -1 引用计数结束。
我自己没有发送任何自动发布的消息,那么我该如何解决这个问题呢?
# Category Event Type RefCt Timestamp Address Size Responsible Library Responsible Caller
0 UITextView Malloc 1 00:09.478.888 0x80c2920 448 UIKit -[UIRuntimeConnection initWithCoder:]
1 UITextView Retain 2 00:09.492.814 0x80c2920 0 UIKit -[UITextView resignFirstResponder]
2 UITextView Autorelease 00:09.492.822 0x80c2920 0 UIKit -[UITextView resignFirstResponder]
3 UITextView Retain 3 00:09.494.396 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
4 UITextView Retain 4 00:09.494.400 0x80c2920 0 Foundation -[NSKeyedUnarchiver _replaceObject:withObject:]
5 UITextView Release 3 00:09.494.403 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
6 UITextView Retain 4 00:09.494.407 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
7 UITextView Release 3 00:09.494.448 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
8 UITextView Autorelease 00:09.494.845 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
9 UITextView Retain 4 00:09.494.848 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
10 UITextView Retain 5 00:09.495.215 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
11 UITextView Retain 6 00:09.495.230 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
12 UITextView Release 5 00:09.495.241 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
13 UITextView Retain 6 00:09.495.255 0x80c2920 0 Foundation -[NSArray(NSArray) initWithCoder:]
14 UITextView Release 5 00:09.495.277 0x80c2920 0 UIKit -[UIView initWithCoder:]
15 UITextView Retain 6 00:09.495.325 0x80c2920 0 UIKit -[UIView(Internal) _addSubview:positioned:relativeTo:]
16 UITextView Release 5 00:09.499.036 0x80c2920 0 UIKit -[UINib instantiateWithOwner:options:]
17 UITextView Retain 6 00:09.499.306 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
18 UITextView Retain 7 00:09.499.325 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
19 UITextView Release 6 00:09.499.336 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
20 UITextView Retain 7 00:09.499.358 0x80c2920 0 Foundation -[NSArray(NSArray) initWithCoder:]
21 UITextView Release 6 00:09.499.385 0x80c2920 0 UIKit -[UINib instantiateWithOwner:options:]
22 UITextView Retain 7 00:09.499.511 0x80c2920 0 Proyecto3 -[EventoDetailViewControllerClass setNombreTextView:]
23 UITextView Release 6 00:09.499.681 0x80c2920 0 Foundation -[NSKeyedUnarchiver dealloc]
24 UITextView Release 5 00:09.499.747 0x80c2920 0 Foundation -[NSKeyedUnarchiver dealloc]
25 UITextView Release 4 00:09.499.762 0x80c2920 0 Foundation -[NSKeyedUnarchiver dealloc]
26 UITextView Release 3 00:09.499.817 0x80c2920 0 Foundation -[NSKeyedUnarchiver dealloc]
27 UITextView Release 2 00:09.499.880 0x80c2920 0 UIKit -[UIRuntimeConnection dealloc]
28 UITextView Retain 3 00:09.534.891 0x80c2920 0 QuartzCore -[CALayer layoutSublayers]
29 UITextView Release 2 00:09.534.895 0x80c2920 0 QuartzCore CALayerLayoutIfNeeded
30 UITextView Retain 3 00:09.607.480 0x80c2920 0 UIKit -[UIView(Hierarchy) subviews]
31 UITextView Retain 4 00:09.607.947 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setView:]
32 UITextView Retain 5 00:09.607.951 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setGestureView:]
33 UITextView Retain 6 00:09.608.655 0x80c2920 0 UIKit -[UITouch view]
34 UITextView Autorelease 00:09.608.658 0x80c2920 0 UIKit -[UITouchesEvent _clearViewForTouch:]
35 UITextView Release 5 00:09.608.661 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setView:]
36 UITextView Release 4 00:09.608.666 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setGestureView:]
37 UITextView Release 3 00:09.608.807 0x80c2920 0 Foundation -[NSAutoreleasePool release]
38 UITextView Retain 4 00:09.609.307 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setView:]
39 UITextView Retain 5 00:09.609.311 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setGestureView:]
40 UITextView Retain 6 00:09.725.677 0x80c2920 0 UIKit -[UITouch view]
41 UITextView Autorelease 00:09.725.680 0x80c2920 0 UIKit -[UITouchesEvent _clearViewForTouch:]
42 UITextView Release 5 00:09.725.684 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setView:]
43 UITextView Release 4 00:09.725.688 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setGestureView:]
44 UITextView Release 3 00:09.725.839 0x80c2920 0 Foundation -[NSAutoreleasePool release]
45 UITextView Zombie -1 00:11.383.459 0x80c2920 0 UIKit -[UIView(Internal) _invalidateSubviewCache]
I'm trying to track a exc-bad-access. I have run Instruments with NSZombie enabled, I get this error log when the app crashes. There is a UIView which is autoreleased four times, but before the autoreleased pool is drained it just has a reference count of 3 so int ends with -1 reference count.
I am not sending any autoreleased messages myself, so how can I solve this?
# Category Event Type RefCt Timestamp Address Size Responsible Library Responsible Caller
0 UITextView Malloc 1 00:09.478.888 0x80c2920 448 UIKit -[UIRuntimeConnection initWithCoder:]
1 UITextView Retain 2 00:09.492.814 0x80c2920 0 UIKit -[UITextView resignFirstResponder]
2 UITextView Autorelease 00:09.492.822 0x80c2920 0 UIKit -[UITextView resignFirstResponder]
3 UITextView Retain 3 00:09.494.396 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
4 UITextView Retain 4 00:09.494.400 0x80c2920 0 Foundation -[NSKeyedUnarchiver _replaceObject:withObject:]
5 UITextView Release 3 00:09.494.403 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
6 UITextView Retain 4 00:09.494.407 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
7 UITextView Release 3 00:09.494.448 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
8 UITextView Autorelease 00:09.494.845 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
9 UITextView Retain 4 00:09.494.848 0x80c2920 0 UIKit -[UIRuntimeConnection initWithCoder:]
10 UITextView Retain 5 00:09.495.215 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
11 UITextView Retain 6 00:09.495.230 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
12 UITextView Release 5 00:09.495.241 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
13 UITextView Retain 6 00:09.495.255 0x80c2920 0 Foundation -[NSArray(NSArray) initWithCoder:]
14 UITextView Release 5 00:09.495.277 0x80c2920 0 UIKit -[UIView initWithCoder:]
15 UITextView Retain 6 00:09.495.325 0x80c2920 0 UIKit -[UIView(Internal) _addSubview:positioned:relativeTo:]
16 UITextView Release 5 00:09.499.036 0x80c2920 0 UIKit -[UINib instantiateWithOwner:options:]
17 UITextView Retain 6 00:09.499.306 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
18 UITextView Retain 7 00:09.499.325 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
19 UITextView Release 6 00:09.499.336 0x80c2920 0 Foundation -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
20 UITextView Retain 7 00:09.499.358 0x80c2920 0 Foundation -[NSArray(NSArray) initWithCoder:]
21 UITextView Release 6 00:09.499.385 0x80c2920 0 UIKit -[UINib instantiateWithOwner:options:]
22 UITextView Retain 7 00:09.499.511 0x80c2920 0 Proyecto3 -[EventoDetailViewControllerClass setNombreTextView:]
23 UITextView Release 6 00:09.499.681 0x80c2920 0 Foundation -[NSKeyedUnarchiver dealloc]
24 UITextView Release 5 00:09.499.747 0x80c2920 0 Foundation -[NSKeyedUnarchiver dealloc]
25 UITextView Release 4 00:09.499.762 0x80c2920 0 Foundation -[NSKeyedUnarchiver dealloc]
26 UITextView Release 3 00:09.499.817 0x80c2920 0 Foundation -[NSKeyedUnarchiver dealloc]
27 UITextView Release 2 00:09.499.880 0x80c2920 0 UIKit -[UIRuntimeConnection dealloc]
28 UITextView Retain 3 00:09.534.891 0x80c2920 0 QuartzCore -[CALayer layoutSublayers]
29 UITextView Release 2 00:09.534.895 0x80c2920 0 QuartzCore CALayerLayoutIfNeeded
30 UITextView Retain 3 00:09.607.480 0x80c2920 0 UIKit -[UIView(Hierarchy) subviews]
31 UITextView Retain 4 00:09.607.947 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setView:]
32 UITextView Retain 5 00:09.607.951 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setGestureView:]
33 UITextView Retain 6 00:09.608.655 0x80c2920 0 UIKit -[UITouch view]
34 UITextView Autorelease 00:09.608.658 0x80c2920 0 UIKit -[UITouchesEvent _clearViewForTouch:]
35 UITextView Release 5 00:09.608.661 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setView:]
36 UITextView Release 4 00:09.608.666 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setGestureView:]
37 UITextView Release 3 00:09.608.807 0x80c2920 0 Foundation -[NSAutoreleasePool release]
38 UITextView Retain 4 00:09.609.307 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setView:]
39 UITextView Retain 5 00:09.609.311 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setGestureView:]
40 UITextView Retain 6 00:09.725.677 0x80c2920 0 UIKit -[UITouch view]
41 UITextView Autorelease 00:09.725.680 0x80c2920 0 UIKit -[UITouchesEvent _clearViewForTouch:]
42 UITextView Release 5 00:09.725.684 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setView:]
43 UITextView Release 4 00:09.725.688 0x80c2920 0 UIKit -[UITouch(UITouchInternal) setGestureView:]
44 UITextView Release 3 00:09.725.839 0x80c2920 0 Foundation -[NSAutoreleasePool release]
45 UITextView Zombie -1 00:11.383.459 0x80c2920 0 UIKit -[UIView(Internal) _invalidateSubviewCache]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当使用 Instruments 分析泄漏时,最好忽略任何显示为归因于 Apple 库的泄漏。要调查的泄漏是那些显示源自您的应用程序代码的泄漏。
自动释放的对象会在池耗尽时被释放。如果您还没有创建任何自己的自动释放对象,那么唯一的自动释放对象必须是Apple自己的,例如
[NSString string]
。我假设您已经运行分析器并解决了所有突出显示的问题?如果没有,那就是第一步。
接下来,查看发生
EXC_BAD_ACCESS
的行。它*可能*提供有关违规对象的线索。很可能该对象或其他对象被过早释放,或者您没有充分保留它们。当这种情况发生时,运行时将在某个时候释放它们。尝试访问它们会导致可怕的
EXC_BAD_ACCESS
。以下是 Lou Franco 对
EXC_BAD_ACCESS
的解释以及如何追踪它的链接:了解 EXC_BAD_ACCESS
When using Instruments to profile Leaks, it's best to ignore any leaks that are shown as attributed to Apple libraries. The Leaks to investigate are those show to originate in your app's code.
Objects that are autoreleased are released when the pool is drained. If you haven't created any of your own objects that are autoreleased, then the only autoreleased objects must be Apple's own, e.g.
[NSString string]
.I assume you have already run the Analyzer and resolved all issues highlighted? If not, that's the first step.
Next, look at the line where the
EXC_BAD_ACCESS
occurs. It*may*offer a clue as to the offending object. Chances are that - or some other - object are being released prematurely, or alternatively you have not retained them sufficiently.When that happens, at some point the runtime will deallocate them. Trying to access them causes the dreaded
EXC_BAD_ACCESS
.Here's the link to Lou Franco's explanation on
EXC_BAD_ACCESS
and how to track it down:Understanding EXC_BAD_ACCESS