Permalink
Browse files

Added auto release pool to keep memory foot print down when retrievin…

…g image from disk in queryDiskCacheForKey
  • Loading branch information...
1 parent 7d6e17c commit 9f4e6915c7625bb94041a6cfef0817aaa361c5b3 Randall Li committed with Apr 4, 2013
Showing with 13 additions and 10 deletions.
  1. +13 −10 SDWebImage/SDImageCache.m
View
@@ -195,18 +195,21 @@ - (void)queryDiskCacheForKey:(NSString *)key done:(void (^)(UIImage *image, SDIm
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]])];
- dispatch_async(dispatch_get_main_queue(), ^
- {
- doneBlock(diskImage, SDImageCacheTypeDisk);
- });
+ 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);
@boazadato

boazadato Nov 20, 2013

Shouldn't this be
doneBlock(diskImage, diskImage ? SDImageCacheTypeDisk : SDImageCacheTypeNone);
...?

+ });
+ }
});
}

0 comments on commit 9f4e691

Please sign in to comment.