1. <legend id='7NUz3'><style id='7NUz3'><dir id='7NUz3'><q id='7NUz3'></q></dir></style></legend>
    • <bdo id='7NUz3'></bdo><ul id='7NUz3'></ul>
    <tfoot id='7NUz3'></tfoot>
  2. <i id='7NUz3'><tr id='7NUz3'><dt id='7NUz3'><q id='7NUz3'><span id='7NUz3'><b id='7NUz3'><form id='7NUz3'><ins id='7NUz3'></ins><ul id='7NUz3'></ul><sub id='7NUz3'></sub></form><legend id='7NUz3'></legend><bdo id='7NUz3'><pre id='7NUz3'><center id='7NUz3'></center></pre></bdo></b><th id='7NUz3'></th></span></q></dt></tr></i><div id='7NUz3'><tfoot id='7NUz3'></tfoot><dl id='7NUz3'><fieldset id='7NUz3'></fieldset></dl></div>

      <small id='7NUz3'></small><noframes id='7NUz3'>

    1. [CALayer 保留]:消息发送到解除分配的实例?

      时间:2024-08-12

        <i id='BOuvr'><tr id='BOuvr'><dt id='BOuvr'><q id='BOuvr'><span id='BOuvr'><b id='BOuvr'><form id='BOuvr'><ins id='BOuvr'></ins><ul id='BOuvr'></ul><sub id='BOuvr'></sub></form><legend id='BOuvr'></legend><bdo id='BOuvr'><pre id='BOuvr'><center id='BOuvr'></center></pre></bdo></b><th id='BOuvr'></th></span></q></dt></tr></i><div id='BOuvr'><tfoot id='BOuvr'></tfoot><dl id='BOuvr'><fieldset id='BOuvr'></fieldset></dl></div>
          <tbody id='BOuvr'></tbody>
          • <legend id='BOuvr'><style id='BOuvr'><dir id='BOuvr'><q id='BOuvr'></q></dir></style></legend>
            <tfoot id='BOuvr'></tfoot>
            • <small id='BOuvr'></small><noframes id='BOuvr'>

              • <bdo id='BOuvr'></bdo><ul id='BOuvr'></ul>
                本文介绍了[CALayer 保留]:消息发送到解除分配的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在我的应用中,当我切换视图时,大约在我第四次切换视图后,我遇到了一个崩溃,上面写着:

                In my app when I am switching views, after about the 4th time I switch views I get a crash that says:

                *** -[CALayer retain]: message sent to deallocated instance 0x6c4ba0
                

                我在 Xcode 中有 NSZombieEnabled,它在切换视图时将我指向这一行:

                I have NSZombieEnabled in Xcode and it points me to this line whenever it switches views:

                [self.view removeFromSuperview];
                

                另外,如果我对 (gdb) 进行回溯,它会给我这个:

                Also if I do a backtrace of the (gdb) it gives me this:

                #0  0x37dd68a0 in ___forwarding___ ()
                #1  0x37d31680 in __forwarding_prep_0___ ()
                #2  0x37d1d026 in CFRetain ()
                #3  0x37d26bb2 in +[__NSArrayI __new::] ()
                #4  0x37d26acc in -[__NSPlaceholderArray initWithObjects:count:] ()
                #5  0x3518e680 in -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] ()
                #6  0x3518e7a4 in -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] ()
                #7  0x3534c40c in __UIViewWillBeRemovedFromSuperview ()
                #8  0x3518dad0 in -[UIView(Hierarchy) removeFromSuperview] ()
                #9  0x000368a6 in __block_global_1 (.block_descriptor=<value temporarily unavailable, due to optimizations>, finished=1 '01') at /Users/bobsComputer/Desktop/Projects/NewApp/MyApp/MyApp3/MyApp3ViewController.mm:135
                #10 0x351a70be in -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] ()
                #11 0x351a181a in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] ()
                #12 0x351a6fb8 in -[UIViewAnimationState animationDidStop:finished:] ()
                #13 0x3354fba6 in CA::Layer::run_animation_callbacks ()
                #14 0x37a91f7a in _dispatch_main_queue_callback_4CF$VARIANT$mp ()
                #15 0x37da72dc in __CFRunLoopRun ()
                #16 0x37d2a4dc in CFRunLoopRunSpecific ()
                #17 0x37d2a3a4 in CFRunLoopRunInMode ()
                #18 0x378a8fcc in GSEventRunModal ()
                #19 0x351ba742 in UIApplicationMain ()
                

                这也是我切换视图的方式,我有一个主视图控制器.然后我使用 ParentView 和协议从我的其他视图控制器中调用这些方法.然后我使用自定义 UIView 动画来切换视图.

                Also this how I switch views, I have a main view controller. I then use a ParentView and protocols to call these methods from my other views controllers. I then use custom UIView animations to switch views.

                有人知道为什么会崩溃吗?

                Does anyone have any ideas why this is crashing?

                谢谢!

                推荐答案

                -[UIView addSubview:] 导致子view被保留,-[UIView removeFromSuperview]导致视图被释放.这是直接来自 Apple 的 UIView 文档.此时,您的一个对象需要保留 CALayer,否则将被释放.

                -[UIView addSubview:] causes the subview to be retained, and -[UIView removeFromSuperview] causes the view to be released. This is direct from Apple's UIView documentation. At that point, one of your objects needs to retain the CALayer or it will be deallocated.

                我假设 CALayer 是您直接创建的.所有 UIView 都与 CALayers 相关联;CALayer 是 UIView 绘制的内容,然后将其 CALayer 合成到屏幕上.如果您不直接使用 CALayers,这是另一个问题的征兆.

                I assumed that the CALayer was created by you directly. All UIViews are associated with CALayers; the CALayer is what a UIView draws into, and then its CALayer is composited onto the screen. If you're not working with CALayers directly, this is a symptom of another problem.

                您描述的核心问题是过度发布.当你应该保留 UIView 时,你可能没有保留它.我建议你运行 Xcode 分析器(在 Xcode 4 中,选择 Product > Analyze)菜单项,看看报告了什么.请特别注意它报告的所有内存管理错误.

                The core problem you're describing is an overrelease. It's possible you're not retaining a UIView when you should. I suggest you run the Xcode analyzer (in Xcode 4, choose the Product > Analyze) menu item and see what gets reported. Pay special attention to all of the memory management errors it reports.

                这篇关于[CALayer 保留]:消息发送到解除分配的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Cocos2d-iphone 支持 iPhone 4 高分辨率 下一篇:Objective-C++ 导入 C++ 类失败,未找到 cassert

                相关文章

                1. <tfoot id='2bIeR'></tfoot>

                    <small id='2bIeR'></small><noframes id='2bIeR'>

                    <legend id='2bIeR'><style id='2bIeR'><dir id='2bIeR'><q id='2bIeR'></q></dir></style></legend>

                    <i id='2bIeR'><tr id='2bIeR'><dt id='2bIeR'><q id='2bIeR'><span id='2bIeR'><b id='2bIeR'><form id='2bIeR'><ins id='2bIeR'></ins><ul id='2bIeR'></ul><sub id='2bIeR'></sub></form><legend id='2bIeR'></legend><bdo id='2bIeR'><pre id='2bIeR'><center id='2bIeR'></center></pre></bdo></b><th id='2bIeR'></th></span></q></dt></tr></i><div id='2bIeR'><tfoot id='2bIeR'></tfoot><dl id='2bIeR'><fieldset id='2bIeR'></fieldset></dl></div>
                      <bdo id='2bIeR'></bdo><ul id='2bIeR'></ul>