Skip to content

Instantly share code, notes, and snippets.

@eventomer
Last active December 26, 2015 09:59
Show Gist options
  • Save eventomer/7133972 to your computer and use it in GitHub Desktop.
Save eventomer/7133972 to your computer and use it in GitHub Desktop.
This is how I tried to implement ipmcc's answer to this question http://stackoverflow.com/questions/19540713/imagewithcgimage-gcd-memory-issue I added the asset library to make sure that the asset object get released and it is not retained somewhere else.
NSURL *asseturl = [_asset valueForProperty:ALAssetPropertyAssetURL];
__block ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:asseturl resultBlock:^(ALAsset *asset) {
__block ALAsset *weakAsset = [asset retain];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
@autoreleasepool {
ALAssetRepresentation* rep = [weakAsset defaultRepresentation];
CGImageRef iref = [rep fullScreenImage];
UIImage* image = [UIImage imageWithCGImage:iref
scale:[rep scale]
orientation:UIImageOrientationUp];
__block UIImage* weakImage = [image retain];
[weakAsset release];
[assetslibrary release];
dispatch_async(dispatch_get_main_queue(), ^(void) {
if (weakImage) {
[self.imageView setImage:weakImage];
[weakImage release];
}
});
}
});
} failureBlock:^(NSError *error) {
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment