我已经能够在运行iOS5的iOS设备上复制低内存崩溃。每次堆栈跟踪指向相同的地方,所以我确切知道问题出在哪里。不幸的是我不知道如何解决它。正如您在下面看到的,当CatViewController收到内存警告时会发生崩溃。在这一点上的看法被强行卸载,然后崩溃发生:低内存警告导致iOS5崩溃 - unloadViewForced
0 libobjc.A.dylib 0x37174f7e objc_msgSend + 22
1 UIKit 0x317eab66 -[UIViewController unloadViewForced:] + 130
2 UIKit 0x31932492 -[UIViewController purgeMemoryForReason:] + 58
3 MyApp 0x001353c0 -[CatViewController didReceiveMemoryWarning] (CatViewController.m:89)
4 Foundation 0x339e34f8 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 12
5 CoreFoundation 0x35178540 ___CFXNotificationPost_block_invoke_0 + 64
6 CoreFoundation 0x35104090 _CFXNotificationPost + 1400
7 Foundation 0x339573e4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 60
8 Foundation 0x33958c14 -[NSNotificationCenter postNotificationName:object:] + 24
9 UIKit 0x318fd26a -[UIApplication _performMemoryWarning] + 74
10 UIKit 0x318fd364 -[UIApplication _receivedMemoryNotification] + 168
11 libdispatch.dylib 0x37ae6252 _dispatch_source_invoke + 510
12 libdispatch.dylib 0x37ae3b1e _dispatch_queue_invoke$VARIANT$up + 42
13 libdispatch.dylib 0x37ae3e64 _dispatch_main_queue_callback_4CF$VARIANT$up + 152
14 CoreFoundation 0x3517f2a6 __CFRunLoopRun + 1262
15 CoreFoundation 0x3510249e CFRunLoopRunSpecific + 294
16 CoreFoundation 0x35102366 CFRunLoopRunInMode + 98
17 GraphicsServices 0x3476d432 GSEventRunModal + 130
18 UIKit 0x31779e76 UIApplicationMain + 1074
19 MyApp 0x00087142 main (main.m:16)
20 MyApp 0x000870c8 start + 32
所以我相信这事做的观点是越来越对iOS5的卸载方式。此视图控制器不会从任何通知中删除自己,因此this solution不起作用。 CatViewController的89号线就是这样的:
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; //this is line 89
}
而且viewDidUnload看起来就像这样:
- (void)viewDidUnload {
[self setBackgroundView:nil];
[self setContentView:nil];
[self setSomeScrollView:nil];
[super viewDidUnload];
}
我如何能处理这种不正常崩溃任何想法?
编辑:这里是另一个崩溃报告的详细信息:
0 CoreFoundation 0x351ac88f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x3717a259 objc_exception_throw + 33
2 CoreFoundation 0x351afa9b -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x351ae915 ___forwarding___ + 301
4 CoreFoundation 0x35109650 _CF_forwarding_prep_0 + 48
5 UIKit 0x317eabdf -[UIViewController unloadViewForced:] + 251
6 UIKit 0x31932499 -[UIViewController purgeMemoryForReason:] + 65
7 MyApp 0x000d541b -[CatViewController didReceiveMemoryWarning] (CatViewController.m:96)
尝试将viewDidUnload中的代码移动到didReceiveMemoryWarning方法中,这是您应该“释放视图控制器使用的任何额外内存”的地方(如文档所述)。 – rdelmar
@rdelmar我试过你的建议。仍坠毁,但在崩溃报告中获得了更多信息。见上面的编辑。 – csoul
我不确定doesNotRecognizeSelector错误是指什么。确保您的set ...方法的名称拼写正确。 – rdelmar