Allow setting a custom memory cost limit for the in-memory NSCache. This can help to keep memory down before memory warnings are sent by the device.

This commit is contained in:
Joshua Gross 2013-11-22 16:16:03 -08:00
parent 417feed2ca
commit c7f2665d05
2 changed files with 10 additions and 0 deletions

View File

@ -32,6 +32,11 @@ typedef enum SDImageCacheType SDImageCacheType;
*/
@interface SDImageCache : NSObject
/**
* The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory.
*/
@property (assign, nonatomic) NSInteger maxMemoryCost;
/**
* The maximum length of time to keep an image in the cache, in seconds
*/

View File

@ -338,6 +338,11 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
}
}
- (void)setMaxMemoryCost:(NSInteger)maxMemoryCost
{
self.memCache.totalCostLimit = maxMemoryCost;
}
- (void)clearMemory
{
[self.memCache removeAllObjects];