I am trying to change FGallery (https://github.com/gdavis/FGallery-iPhone). I need this to read images from a camera roll, but I get a memory leak.
Old code (path is the location of the file):
@autoreleasepool { NSString *path = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] bundlePath],_thumbUrl]; _thumbnail = [UIImage imageWithContentsOfFile:path]; _hasThumbLoaded = YES; _isThumbLoading = NO; [self performSelectorOnMainThread:@selector(didLoadThumbnail) withObject:nil waitUntilDone:YES]; }
My code (path is the URL of the library approval):
@autoreleasepool { ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) { ALAssetRepresentation *rep = [myasset defaultRepresentation]; CGImageRef iref = [rep fullResolutionImage]; if (iref) { _thumbnail = [UIImage imageWithCGImage:iref]; _hasThumbLoaded = YES; _isThumbLoading = NO; [self performSelectorOnMainThread:@selector(didLoadThumbnail) withObject:nil waitUntilDone:YES]; } }; ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) { NSLog(@"booya, cant get image - %@",[myerror localizedDescription]); }; NSURL *asseturl = [NSURL URLWithString:_thumbUrl]; [assetslibrary assetForURL:asseturl resultBlock:resultblock failureBlock:failureblock]; } }
For the same images, I get a large memory allocation (-didReceiveMemoryWarning) that breaks the program in my code, but not when using the source code.
Any ideas why?
PS I use ARC, and made an automatic transition for FGallery. It works great for local application images, but as said, I can't get it to work with camera images.
change 1: program crash
source share