UIViewController purgeMemoryForReason:在 iOS 5 上崩溃 [英] UIViewController purgeMemoryForReason: Crashing on iOS 5

查看:13
本文介绍了UIViewController purgeMemoryForReason:在 iOS 5 上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在运行 iOS 5 的 iPad 和 iPad 2 上的 Crashlytics 中经常看到这种崩溃.看起来它是由内存警告引起的,但堆栈跟踪没有引用我的任何应用程序代码,只是 iOS 框架:

So I've been seeing this crash pretty frequently in Crashlytics, both on iPad and iPad 2, running iOS 5. It looks like it's caused by a memory warning, but the stack trace doesn't reference any of my application code, just iOS frameworks:

0    libobjc.A.dylib    objc_msgSend + 15
1    UIKit          -[UIViewController purgeMemoryForReason:] + 64
2    Foundation     __57-[NSNotificationCenter addObserver: selector: name: object:]_block_invoke_0 + 18
3    CoreFoundation     ___CFXNotificationPost_block_invoke_0 + 70
4    CoreFoundation     _CFXNotificationPost + 1406
5    Foundation     -[NSNotificationCenter postNotificationName: object: userInfo:] + 66
6    Foundation     -[NSNotificationCenter postNotificationName: object:] + 30
7    UIKit          -[UIApplication _performMemoryWarning] + 80
8    UIKit          -[UIApplication _receivedMemoryNotification] + 174
9    libdispatch.dylib  _dispatch_source_invoke + 516
10   libdispatch.dylib  _dispatch_queue_invoke + 50
11   libdispatch.dylib  _dispatch_main_queue_callback_4CF + 156
12   CoreFoundation     __CFRunLoopRun + 1268
13   CoreFoundation     CFRunLoopRunSpecific + 300
14   CoreFoundation     CFRunLoopRunInMode + 104
15   GraphicsServices   GSEventRunModal + 156
16   UIKit          UIApplicationMain + 1090
17   500px iOS      main.m line 12

我在谷歌上搜索了高低,但找不到任何解决方案.看起来这是由过度释放 UIViewController 实例引起的,但我使用的是 ARC,所以我不明白这是怎么回事.

I've googled high and low but can't find any solutions to this. It looks like this is caused by over-releasing a UIViewController instance, but I'm using ARC, so I don't see how that could be the case.

我什至不知道如何解决这个问题.我什至无法判断是哪个 UIViewController 子类导致了这个问题.我已经尝试在模拟器和设备上重现该问题,但我找不到导致它的原因.有没有人看到过这样的事情或有关于如何重现问题的建议?

I'm at a loss of how to even approach this. I can't even tell which UIViewController subclass is causing the issue. I've tried reproducing the problem in the simulator and on the device, but I can't find what causes it. Has anyone seen anything like this or have suggestions on how to approach reproducing the issue?

推荐答案

我想我已经解决了这个问题.我在想,问题不是 UIViewController 视图的卸载,而是实际低内存警告通知的发布.在我的代码中有几个实例调用 [[NSNotificationCenter defaultCenter] removeObserver:self].这在 dealloc 方法中很好,但在 viewDidUnload 方法中有两个实例.

I think I've solved the issue. I was thinking about it, and the problem isn't the unloading of the UIViewController view, it's the posting of the actual low memory warning notification. There are several instances in my code where I call [[NSNotificationCenter defaultCenter] removeObserver:self]. This is fine in the dealloc method, but there were two instances of this in viewDidUnload methods.

当我在 UIViewController 之一的 didReceiveMemory 中的断点没有被击中时,我注意到了这一点.viewDidUnload 中的代码也将 self 从其他系统通知中注销,详情请参见 此处.

I noticed this when my breakpoint in didReceiveMemory of one of the UIViewController's wasn't getting hit. The code in viewDidUnload was also unregistering self from other, system notifications as well, as detailed here.

在我确认崩溃随着新更新停止之前,我不会将此标记为已接受的答案.

I'm not going to mark this as an accepted answer until I verify that the crashes stop with the new update.

更新:我已经通过 Crashlytics 确认问题已解决!

UPDATE: I've verified with Crashlytics that the problem has been fixed!

这篇关于UIViewController purgeMemoryForReason:在 iOS 5 上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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