From 9f4e6915c7625bb94041a6cfef0817aaa361c5b3 Mon Sep 17 00:00:00 2001 From: Randall Li Date: Thu, 4 Apr 2013 15:33:23 -0400 Subject: [PATCH] Added auto release pool to keep memory foot print down when retrieving image from disk in queryDiskCacheForKey --- SDWebImage/SDImageCache.m | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index f3d5852f..dbb0bf5e 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -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); - }); }); }