Added auto release pool to keep memory foot print down when retrieving image from disk in queryDiskCacheForKey

This commit is contained in:
Randall Li 2013-04-04 15:33:23 -04:00 committed by Olivier Poitrey
parent 7d6e17c43c
commit 9f4e6915c7
1 changed files with 13 additions and 10 deletions

View File

@ -195,18 +195,21 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
dispatch_async(self.ioQueue, ^
{
UIImage *diskImage = [UIImage decodedImageWithImage:SDScaledImageForPath(key, [NSData dataWithContentsOfFile:[self cachePathForKey:key]])];
if (diskImage)
@autoreleasepool
{
CGFloat cost = diskImage.size.height * diskImage.size.width * diskImage.scale;
[self.memCache setObject:diskImage forKey:key cost:cost];
UIImage *diskImage = [UIImage decodedImageWithImage:SDScaledImageForPath(key, [NSData dataWithContentsOfFile:[self cachePathForKey:key]])];
if (diskImage)
{
CGFloat cost = diskImage.size.height * diskImage.size.width * diskImage.scale;
[self.memCache setObject:diskImage forKey:key cost:cost];
}
dispatch_async(dispatch_get_main_queue(), ^
{
doneBlock(diskImage, SDImageCacheTypeDisk);
});
}
dispatch_async(dispatch_get_main_queue(), ^
{
doneBlock(diskImage, SDImageCacheTypeDisk);
});
});
}