在应用来自后台之后,“将消息发送到解除分配的实例" [英] After app comes from background "Message sent to deallocated instance"

查看:38
本文介绍了在应用来自后台之后,“将消息发送到解除分配的实例"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个奇怪的错误.我们正在将iOS 5与ARC配合使用.当NSZombiesEnabled设置为true并将应用程序插入调试器时,我们会收到此错误(该错误也通常发生,但不一致)

I'm getting an odd error. We are using iOS 5 with ARC. When NSZombiesEnabled is set to true and the app is plugged into the debugger we get this error (it happens normally too but not as consistently)

2012-07-04 11:25:17.161 Trivial[624:707] -[vcCurrentGames gamesLoaded:] [Line 284] Found 62 games that are my turn.
2012-07-04 11:25:17.162 Trivial[624:707] -[vcCurrentGames gamesLoaded:] [Line 285] Found 26 games that are their turn.
2012-07-04 11:25:17.169 Trivial[624:707] -[vcCurrentGames tableView:heightForHeaderInSection:] [Line 409] Height 1: 29
2012-07-04 11:25:17.171 Trivial[624:707] *** -[vcDashboard retain]: message sent to deallocated instance 0xf62c3c0

我们不会在任何地方保留仪表板(ARC不允许保留).仅在从后台加载应用后才会发生这种情况. vcCurrentGames实际上是仪表板上的UITableView.这让我感到更加奇怪,因为如果仪表板被取消分配,那么为什么要加载UITableView?

We are not retaining the dashboard anywhere (ARC doesn't allow retain). This only happens after the app is loaded from the background. vcCurrentGames is actually a UITableView on the dashboard. Which makes it even more odd to me, because if the dashboard is dealloced then why is it's UITableView loading?

我已经阅读了一些.仪表板在应用程序委托中定义为属性:

I've read a little bit about this. The dashboard is defined in the app delegate as a property:

@property (nonatomic, strong) vcDashboard *vDashboard;

我试图使它变弱,以便将其归零,但这也不起作用.有人可以告诉我为什么要取消分配它,或者为什么要在取消分配后保留vcDashboard吗?

I've attempted making this weak so that it will zero out, but that doesn't work either. Can someone tell me why it's being dealloced or why it's trying to retain vcDashboard after it's been dealloced?

在应用程序委托中,我这样声明:

In app delegate I declare it like this:

UIViewController *viewController = [[vcDashboard alloc] initWithNibName:@"vcDashboard" bundle:nil];
self.vDashboard = (vcDashboard *)viewController;

推荐答案

在初始化期间可能出了点问题.您将vcDashboard分配给UIViewController,然后将该控制器转换为适当的类.从理论上讲这应该没问题,但我以前从未见过这种模式.标准方式是:

Maybe something goes wrong during initialization. You assign the vcDashboard to a UIViewController and then cast that controller to the appropriate class. While theoretically this should be fine, I have never seen this pattern before. The standard way is:

self.vDashboard = (vcDashboard*) [[vcDashboard alloc] init];

假定笔尖名称为"vcDashboard"(似乎是这种情况),并且笔尖中的类也为"vcDashboard".
(顺便说一句,约定是将类名大写.)

assuming that the nib name is "vcDashboard" (as seems to be the case) and that the class in the nib is also "vcDashboard".
(BTW, the convention is to capitalize class names.)

此外,在应用程序进入后台后,也许vcDashboard会被释放.无论如何,当应用程序从后台返回时,都不能保证它仍然存在.您是否考虑过惰性实例化?

Also, after the app goes into the background, maybe vcDashboard gets deallocated. In any case, it is not guaranteed that it is still there when the app comes back from background. Did you consider lazy instantiation?

// in app delegate
-(vcDashboard*)vDashboard {
   if (_vcDashboard) {
     return _vcDashboard;
   }

   vcDasboard vc = [[vcDashboard alloc] init];
   // more initialization code
   _vcDashboard = vc;
   return vc;
}

这篇关于在应用来自后台之后,“将消息发送到解除分配的实例"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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