如何弄清楚哪些UIView僵尸CALayer属于Xcode 4的僵尸工具?

问题描述:

我一天毁了此消息:如何弄清楚哪些UIView僵尸CALayer属于Xcode 4的僵尸工具?

*** -[CALayer retainCount]: message sent to deallocated instance 0x656b260 

由于我没有在这种情况下创建的CALayer自己,那只能是这可能是从一个UIButton任何一个UISlider一个UIView的CALayer的。所以我得到了great answer from Jeff to my question about how to trace this down in Xcode 4

杰夫建议按Command + I启动Profiler,然后选择僵尸工具。事实上,僵尸工具停在了CALayer上,并向我扔了一个更有用的堆栈跟踪。

但是,堆栈跟踪并没有那么有用,因为它并没有告诉我哪一个反对僵尸真的是。每个UIView都有一个CALayer,但重点是我不会自己创建这些CALayer实例。所以在这种情况下,目标是要知道CALayer属于哪个UIView(按钮,滑块等)。

0 libSystem.B.dylib calloc 
    1 libobjc.A.dylib class_createInstanceXcode4 
    2 CoreFoundation +[NSObject(NSObject) allocWithZone:] 
    3 CoreFoundation +[NSObject(NSObject) alloc] 
    4 UIKit -[UIView _createLayerWithFrame:] 
    5 UIKit UIViewCommonInitWithFrame 
    6 UIKit -[UIView initWithFrame:] 
    7 UIKit -[UIControl initWithFrame:] 
    8 UIKit -[UIButton initWithFrame:] 
    9 UIKit +[UIButton buttonWithType:] 
    10 TestApp +[CCButton buttonWithNormalImage:pressedImageName:] /Users/tom/Documents/testcomp/Projects/TestApp/Xcode4/Classes/CCButton.m:267 
    11 TestApp -[ConfigView setupCommitBlade] /Users/tom/Documents/testcomp/Projects/TestApp/Xcode4/Classes/ConfigView.m:606 
    12 TestApp -[ConfigView initWithRootVC:] /Users/tom/Documents/testcomp/Projects/TestApp/Xcode4/Classes/ConfigView.m:714 
    13 TestApp -[TestAppViewController loadConfigViewIfNeeded] /Users/tom/Documents/testcomp/Projects/TestApp/Xcode4/Classes/TestAppViewController.m:69 
    14 TestApp -[TestAppViewController viewDidLoad] /Users/tom/Documents/testcomp/Projects/TestApp/Xcode4/Classes/TestAppViewController.m:293 
    15 UIKit -[UIViewController view] 
    16 TestApp -[TestAppAppDelegate application:didFinishLaunchingWithOptions:] /Users/tom/Documents/testcomp/Projects/TestApp/Xcode4/Classes/TestAppAppDelegate.m:238 
    17 UIKit -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] 
    18 UIKit -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 
    19 UIKit -[UIApplication handleEvent:withNewEvent:] 
    20 UIKit -[UIApplication sendEvent:] 
    21 UIKit _UIApplicationHandleEvent 
    22 GraphicsServices PurpleEventCallback 
    23 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ 
    24 CoreFoundation __CFRunLoopDoSource1 
    25 CoreFoundation __CFRunLoopRun 
    26 CoreFoundation CFRunLoopRunSpecific 
    27 CoreFoundation CFRunLoopRunInMode 
    28 UIKit -[UIApplication _run] 
    29 UIKit UIApplicationMain 
    30 TestApp main /Users/tom/Documents/testcomp/Projects/TestApp/Xcode4/main.m:14 
    31 TestApp start 

也许有人可以指出一个教程或视频,它展示了如何在Xcode4中描述这样的问题?据我记得,Xcode 3真的指出哪个反对它,但在这里我只是看不到邪恶在哪里。必须有一些经验法则才能正确解释堆栈跟踪/或者僵尸工具为什么不直接指出僵尸出现的代码行的一个很好的理由。

您需要在Edit Scheme> Diagnostics面板中打开malloc堆栈日志记录。然后,当你让僵尸错误,你可以在gdb的控制台做到这一点:

info malloc-history -exact 0x656b260 

从僵尸消息使用的地址,当然。每次运行可能会有所不同。

+0

太棒了!但我认为我没有使用GDB。 Xcode 4现在不是基于LLVM吗? – dontWatchMyProfile

+0

无论您使用哪种编译器,您仍然可以在Xcode中使用GDB。 –

+0

那么僵尸工具不会自动打开这个标志? – dontWatchMyProfile