UIImageJPEGRepresentation填充内存

时间:2014-08-22 11:28:57

标签: ios memory-management

以下代码将内存泵入极限。我加载了大约100张图像,内存为200MB。如果我把应用程序放在后台和前台,那么将内存从200MB清除到大约10MB。我怎样才能释放内存? @autoreleasepool无法正常工作

@autoreleasepool {
        NSData *imgData = UIImageJPEGRepresentation(image, 0.5);
        NSString *name    = [[NSUUID UUID] UUIDString];
        NSString *path    = [NSString stringWithFormat:@"Documents/%@.jpg", name];
        NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:path];
        if ([imgData writeToFile:jpgPath atomically:YES]) {
            data.imagePath = path;
            [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreWithCompletion:nil];
        } else {
            [[[UIAlertView alloc] initWithTitle:@"Error"
                                        message:@"There was an error saving your photo. Try again."
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles: nil] show];
        }
        imgData = nil;
}

0 个答案:

没有答案