[UINavigationController retain]:发送给deallocated实例的消息

编程入门 行业动态 更新时间:2024-10-28 18:29:15
本文介绍了[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实例的消息

本文发布于:2023-11-25 08:45:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629092.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实例   发送给   消息   UINavigationController   retain

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!