我試圖生成圖形並逐個截取屏幕截圖。該應用程序一次正常工作,然後當我第二次嘗試再次捕獲屏幕截圖時,應用程序崩潰,說應用程序由於內存錯誤而終止。這隻發生在iOS8而不發生在iOS7中。這裏捕捉屏幕截圖的代碼,在線崩潰 - [view.layer renderInContext:context];
應用程序在高峯使用時使用124 MB,並且在崩潰之前沒有生成內存警告。即使沒有其他應用程序在後臺運行,應用程序也會在iOS 8上崩潰。如果我註釋掉上面的行,應用程序根本不會崩潰,但截取的截圖不是完整的屏幕。由於內存錯誤,iOS8上的應用程序崩潰
- (BOOL)captureView:(UIView *)view forGraph:(NSString *)graphName
{
BOOL isImageCpatured = NO;
@try {
CGRect rect = view.bounds;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
imageRef = CGImageCreateWithImageInRect([img CGImage], CGRectMake(0, 113, 1024, 532));
}
else {
imageRef = CGImageCreateWithImageInRect([img CGImage], CGRectMake(0, 93, 1024, 532));
}
img = nil;
UIImage *image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
NSData *pngData = UIImagePNGRepresentation(image);
[pngData writeToFile:[Utility_Class documentsPathForFileName:[NSString stringWithFormat:@"%@BG.png",graphName]] atomically:YES];
pngData = nil;
image = nil;
isImageCpatured = YES;
}
@catch (NSException *exception) {
return isImageCpatured;
}
@finally {
}
return isImageCpatured;
}
什麼可能是錯的?我無法找到任何解決方案。我發現內存壓力與內存錯誤不同。但沒有解決方法如何解決它。即使captureView函數在@autorelease池中被調用。
這是在iOS8上生成的未知崩潰日誌。它從不崩潰的iOS7。
Incident Identifier: 24F29058-7D47-40B6-87B4-2183220DB55B
CrashReporter Key: 6079e634bf7aeebb0e4d9ea95336cb33b0fc49dd
Hardware Model: iPad4,1
OS Version: iPhone OS 8.0 (12A365)
Kernel Version: Darwin Kernel Version 14.0.0: Tue Aug 19 15:09:47 PDT 2014; root:xnu-2783.1.72~8/RELEASE_ARM64_S5L8960X
Date: 2014-09-25 18:21:25 +0530
Time since snapshot: 88 ms
Free pages: 2219
Active pages: 96945
Inactive pages: 48102
Speculative pages: 314
Throttled pages: 0
Purgeable pages: 2
Wired pages: 77304
File-backed pages: 40758
Anonymous pages: 104603
Compressions: 1467794
Decompressions: 158957
Compressor Size: 24980
Uncompressed Pages in Compressor: 119797
Page Size: 16384
Largest process: my application Name
>請您提供崩潰日誌? – 2014-09-25 13:13:40
添加了崩潰日誌。 – 2014-09-26 05:11:14
我也有一個應用程序崩潰,看起來隨機,在iOS 8但不是iOS 7. V奇怪... – mm2001 2014-09-26 05:20:45