While NSCache
never responded to memory warnings, I found that it generally responded to true memory pressure. The failure to respond to memory warnings has always been a bit of an annoyance (e.g. you couldn't just use the "simulate memory warning" to test the behavior of an app in memory pressure).
Having said that, I see the same behavior you describe. iOS 7 seems to have changed the NSCache
behavior.
Personally, I just have simple-minded NSCache
subclass that just removes all of the objects upon receiving the UIApplicationDidReceiveMemoryWarningNotification
notification:
@implementation AutoPurgeCache
- (id)init
{
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllObjects) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
}
@end