我已經能夠在運行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