所以我在运行 iOS 5 的 iPad 和 iPad 2 上的 Crashlytics 中经常看到这种崩溃。看起来它是由内存警告引起的,但堆栈跟踪没有引用我的任何应用程序代码,只是 iOS 框架:
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,所以我不明白这是怎么回事。
我什至不知道如何处理这个问题。我什至不知道是哪个 UIViewController 子类导致了这个问题。我试过在模拟器和设备上重现这个问题,但我找不到导致它的原因。有没有人见过这样的事情或对如何重现问题有建议?
最佳答案
我想我已经解决了这个问题。我在考虑它,问题不在于 UIViewController View 的卸载,而是实际内存不足警告通知的发布。在我的代码中有几个调用 [[NSNotificationCenter defaultCenter] removeObserver:self] 的实例。这在 dealloc 方法中很好,但在 viewDidUnload 方法中有两个实例。
当我在其中一个 UIViewController 的 didReceiveMemory 中的断点没有被击中时,我注意到了这一点。 viewDidUnload 中的代码也从其他系统通知中取消注册 self,详见 here .
我不会将此标记为已接受的答案,直到我确认崩溃会随着新更新而停止。
更新:我已通过 Crashlytics 确认问题已得到解决!
关于objective-c - UIViewController purgeMemoryForReason : Crashing on iOS 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8773497/