我使用UIWebView從電子郵件中加載ppt文件,並使用renderInContext將ppt頁面轉換爲圖像:api在主線程的do while循環中。使用renderInContext呈現webview圖層時iOS應用崩潰:api
它工作正常,當我加載小於50張幻燈片小ppt文件。當我加載100頁PPT文檔時,我的應用崩潰了。崩潰發生在第83次renderInContext:API(從UIWebview呈現UILayer)。
下面是我在ARC應用程序中使用的一段代碼。
do
{
@autoreleasepool
{
NSLog(@"Image Index: %d",i);
UIGraphicsBeginImageContext(CGSizeMake(768.0f, 576.0f));
CGContextRef ctxCurrentGraphics = UIGraphicsGetCurrentContext();
[webView.layer renderInContext:ctxCurrentGraphics];
CGContextSetInterpolationQuality(ctxCurrentGraphics, kCGInterpolationHigh);
CGContextSetRenderingIntent(ctxCurrentGraphics, kCGRenderingIntentDefault);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
/******* Each snap shot been inserted to db before new snapshot created ********/
if (image != nil)
{
[[DataManager instance] insertImportedImageToDb:image importFileName:filename ...];
slideID++;
seqID++;
}
[webView.scrollView scrollRectToVisible:CGRectMake(0.0f, (i * 581.3) , webView.bounds.size.width, webView.bounds.size.height) animated:NO];
scrolloffset = scrolloffset + 581.3;
i++;
/***** check if ppt contains only one page ****/
if (webView.scrollView.contentSize.height == 1004.0 || webView.scrollView.contentSize.height == 1005.0)
{
break;
}
image = nil;
}
}
while (scrolloffset <= webView.scrollView.contentSize.height);
該應用僅在設備(iOS6)上崩潰。我嘗試了所有替代方案,我發現堆棧溢出像清除上下文,使用@autoreleasepool等
任何人都可以幫助我有什麼辦法可以優化內存使用或有任何替代renderInContext:它看起來像API這個API有內存泄漏。
EDIT1:大多數時候,應用程序收到「內存不足警告」,但兩次我看到下面的崩潰日誌:
Last Exception Backtrace:
0 CoreFoundation 0x316aa29e 0x315e8000 + 795294
1 libobjc.A.dylib 0x3954e97a 0x39546000 + 35194
2 CoreFoundation 0x316aa1c0 0x315e8000 + 795072
3 UIKit 0x3389dd5a 0x334af000 + 4123994
4 MyApplication 0x000c590c 0xa3000 + 141580
5 MyApplication 0x000c4d26 0xa3000 + 138534
6 Foundation 0x31fc1f4e 0x31f10000 + 728910
7 CoreFoundation 0x3167f5da 0x315e8000 + 619994
8 CoreFoundation 0x3167f28c 0x315e8000 + 619148
9 CoreFoundation 0x3167defc 0x315e8000 + 614140
10 CoreFoundation 0x315f0eb8 0x315e8000 + 36536
11 CoreFoundation 0x315f0d44 0x315e8000 + 36164
12 GraphicsServices 0x351a52e6 0x351a0000 + 21222
13 UIKit 0x335062fc 0x334af000 + 357116
14 MyApplication 0x000a8c60 0xa3000 + 23648
15 libdyld.dylib 0x39985b1c 0x39984000 + 6940
感謝, 西瓦
它給了什麼錯誤? –
更新我的問題與錯誤的詳細信息。大部分時間,應用都收到了「低內存警告」。 – Srivathsa