[UINavigationController retain]:发送给deallocated实例的消息 [英] [UINavigationController retain]: message sent to deallocated instance

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

问题描述

我的应用程序在模拟器中模拟内存警告时崩溃错误:

My application crashes when simulating Memory warning in simulator with error:


[UINavigationController retain]:发送到解除分配实例的消息

[UINavigationController retain]: message sent to deallocated instance

我正在使用ARC。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
      UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     _window = window;


    [self startWithFlash];

     return YES;
}

- (void)startWithFlash
{
    [self.window.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

    __weak typeof (self) weakSelf = self;

     WPRSplashViewController *splashViewController = [[WPRSplashViewController alloc] initWithNibName:@"WPRSplashView" bundle:nil doneCallback:^{
        [weakSelf startApplication];
    }];


     self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:splashViewController];

    [self.window makeKeyAndVisible];
}

- (void)startApplication
{    
     WPRMainViewController *mainViewController = [[WPRMainViewController alloc] init];
     UINavigationController * controller = [[UINavigationController alloc] initWithRootViewController:mainViewController];

     self.menuController = [[PHMenuViewController alloc] initWithRootViewController:controller
                                                                   atIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

     self.window.rootViewController = self.menuController;

    [self.window makeKeyAndVisible];
}

当我打电话给应用程序的某个地方时会发生这种情况:

This happens when somewhere in the app I call:


[((WPRAppDelegate *)[UIApplication sharedApplication] .delegate)startWithFlash];

[((WPRAppDelegate*) [UIApplication sharedApplication].delegate) startWithFlash];

在模拟内存警告之后。

启用NSZombie运行配置文件工具我得到以下跟踪:

Running Profile Tools with NSZombie enabled I get the following trace:

这不是唯一有这种崩溃的地方。在我使用UINavigationController作为视图控制器的包装器的每个地方,我将它作为模态视图呈现,在模拟内存警告后,我得到了这个崩溃。

This is not the only place with such crash. In every place where I use UINavigationController as wrapper for view controller and I present it as modal view, after simulating memory warning I get this crash.

我的问题非常类似于其他地方我在这里发布了另一个问题,但没有找到合理的解决方案:类似问题

I had very similar issue in other place for which I've posted here another question but did not find a reasonable solution: Similar issue

推荐答案

经过数天的调查后,我发现了所有这些崩溃的原因,包括一个在iOS内存警告发送到解除分配的UIViewController中描述

Finally after days of investigations I've found a reason to all these crashes including the one described in "iOS memory warning sent to deallocated UIViewController"

问题来自PHAirViewController项目。我仍然没有找到真正的原因,只是简单地在 PHAirViewController.m 中评论 - (void)dealloc 函数文件是神奇的。

The problem came out from PHAirViewController project. I still did not find out a real reason, but simply commenting out - (void)dealloc function in PHAirViewController.m file did the magic.

我在运行仪器检测NSZombies时遇到的主要问题。所有跟踪都指向系统类,如UINavigationController,UIImagePickerViewController等......由于这个原因,我开始为父控制器禁用ARC。它在某些地方有所帮助,但有些地方并没有。

The main headache I got when was running Instruments to detect NSZombies. All traces were pointing to system classes like UINavigationController, UIImagePickerViewController etc... Due to this I started disabling ARC for parent controllers. In some places it helped but in some it didn't.

经过大量的伏都教后,我发现每个类(包括系统类)都在实现 UIViewCOntroller(PHAirViewController)类别虽然 - (void)dealloc 总是在解雇它们时调用它。

After a lot of voodoo I found out that every class (including system classes) was implementing UIViewCOntroller(PHAirViewController) Category and though - (void)dealloc function was always called on dismissing them.

现在唯一剩下的就是理解为什么这个函数正在生成NSZombies。有趣的是,仅仅评论其内容(只有一行: self.phSwipeHandler = nil )不会产生同样的效果。

Now the only thing left is to understand why this function is generating NSZombies. The interesting thing is that just commenting its content (which have only one line: self.phSwipeHandler = nil) does not have the same effect.

这篇关于[UINavigationController retain]:发送给deallocated实例的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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