0

I'm adding images from the Asset Library using this code. I'm 99% sure (from Instruments) that the iref isn't being released and a new CG Image is being retained in memory every time I call this method. However, if I add: CGImageRelease(iref) the app crashes.

-(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];

}
3
  • What code is in setBackgroundWithImage?
    – Wain
    Oct 29, 2013 at 23:18
  • it's a very long chain of void methods, which is too long to post. However, the CG Image is created (I know this from Instruments) before the first line of setBackgroundwithImage is ran.
    – Eric
    Oct 29, 2013 at 23:22
  • @Eric Hi Eric, I am having the same issue, have you solved this?
    – Jensen
    Jan 31, 2014 at 5:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.