[CALayer retain]:消息发送到释放实例? [英] [CALayer retain]: message sent to deallocated instance?

查看:680
本文介绍了[CALayer retain]:消息发送到释放实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,当我切换视图,大约第4次我切换视图后,我得到一个崩溃说:

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 '\001') 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:] 保留, - [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,选择产品>分析)菜单项,看看有什么报告。特别注意它报告的所有内存管理错误。

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 retain]:消息发送到释放实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆