从ALAsset库保留CG图像导致内存崩溃

时间:2013-10-29 23:15:56

标签: ios iphone memory core-graphics alassetslibrary

我正在使用此代码从资源库添加图片。我99%肯定(来自Instruments),每次调用此方法时iref都没有被释放,并且新的CG Image被保留在内存中。但是,如果我添加:CGImageRelease(iref)应用程序崩溃。

-(void)setBackgroundWithPhotoURL: (NSURL*)photoURL
{
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
    {
        @autoreleasepool {
            ALAssetRepresentation *rep = [myasset defaultRepresentation];
            CGImageRef iref = [rep fullResolutionImage];

            UIImage *selectedBackground = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
                if (selectedBackground) {
                    [self setBackgroundWithImage:selectedBackground orColor:nil];
                }
            }
    };
    ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
    {
        NSLog(@"Can't get image - %@",[myerror localizedDescription]);
    };

    ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
    [assetslibrary assetForURL:photoURL resultBlock:resultblock failureBlock:failureblock];

}

0 个答案:

没有答案