我正在使用此代码从资源库添加图片。我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];
}