I am using AssetsLibrary.framework for fetching images from device gallery.I successfully fetched all images from gallery and displayed on my table view.Problem comes when I scroll up and down many times , I receive a memory issue warning getting printed on console and after some time it gets crashed saying CRASHED DUE TO MEMORY PRESSURE.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
ALAsset *asset = [self.images objectAtIndex:indexPath.row];
ALAssetRepresentation *representation = [asset defaultRepresentation];
image=[UIImage imageWithCGImage:[representation fullResolutionImage]];
[selectedAllImages addObject:image];
url = [representation url];
NSURL *imageURL=url;
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *representation = [myasset defaultRepresentation];
fileName = [representation filename];
cell.cellLabel.text=fileName;
};
assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:imageURL
resultBlock:resultblock
failureBlock:nil];
[cell.cellImageView setImage:[UIImage imageWithCGImage:[asset thumbnail]]];
return cell;
}
So I need help where the mistake is?Thanks
Why do you getting fullResolutionImage in cellForRowAtIndexPath method? And putting into selectedAllImages array.. it seems like selectedAllImages array fills by fullresolutionimages infinity (during scrolling).
Why you create assetslibrary and request for same asset (which have same url)?
I think you should simplify your 'cellForRowAtIndexPath' method, to be more lightweight during scrolling. Something like this: