0

我正在使用此代码从资产库中添加图像。我有 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];

}
4

0 回答 0