我從崩潰報告中symbolicated堆棧跟蹤從我的iPad應用程序(節選):在我的iPad應用程序中導致此EXC_CRASH的原因是什麼?
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
0 ImageIO 0x34528eb4 _CGImagePluginIdentifyPNG + 0
1 ImageIO 0x34528d90 _CGImageSourceBindToPlugin + 368
2 ImageIO 0x34528bda CGImageSourceGetCount + 26
3 UIKit 0x341b8f66 _UIImageRefAtPath + 366
4 UIKit 0x342650ce -[UIImage initWithContentsOfFile:] + 50
5 UIKit 0x342b0314 +[UIImage imageWithContentsOfFile:] + 28
6 DesignScene 0x00013a2a -[LTImageCache fetchImageforURL:] (LTImageCache.m:37)
…
這裏是-[LTImageCache fetchImageforURL:]
內容:
- (UIImage *)fetchImageforURL:(NSString *)theUrl {
NSString *key = theUrl.md5Hash;
return [UIImage imageWithContentsOfFile:[self filenameForKey:key]];
}
和-[LTImageCache filenameForKey:]
內容:
- (NSString *) filenameForKey:(NSString *) key {
return [_cacheDir stringByAppendingPathComponent:key];
}
ivar創建並保留在-init
。所以問題是,造成這次事故的原因是什麼?是,這個問題:
- 的
-[LTImageCache filenameForKey:]
返回值需要保留(它的自動釋放) - 未處理的異常某處(
+[UIImage imageWithContentsOfFile:]
要求返回nil
如果圖像是無法識別) - 別的東西......我'猜出來了
我會認爲autoreleased的價值會很好。實際上,這段代碼幾個月來一直工作正常,而且這種方法在會話中被稱爲100次。在非常特殊的情況下,這是一次罕見的崩潰(該應用程序在一夜之間被加載,早上解鎖iPad時發生崩潰)。
這是什麼原因造成的?
該文件已下載。在iOS中是`CGImageSource`嗎?該文檔僅提及Mac OS X 10.4或更高版本。無論如何,這隻發生在一個非常特殊的情況下(當應用程序被打開,但iPad被鎖定在一夜之間)。所以我想知道是否應該嘗試捕獲異常並刪除文件。這看起來合理嗎? – theory 2011-02-22 04:21:42