How to trigger a memory alert
4 answers
In the simulator, you can go to the Hardware section and select Simulate Memory Alert.
If you're trying to do this on a real iOS device, this blog post explains how to send a memory alert to your code.
+7
source to share
I like to put something hidden in my application in debug mode, such as triple clicking on a specific area of my interface, which calls this:
- (void) simulateMemoryWarning:(UITapGestureRecognizer *)gesture {
[[NSNotificationCenter defaultCenter] postNotificationName:TriggerManualMemoryWarningNotification object:nil];
}
Then in my app div:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveManualMemoryWarning:) name:TriggerManualMemoryWarningNotification object:nil];
and
- (void) didReceiveManualMemoryWarning:(NSNotification *)notification {
#ifdef DEBUG
SEL memoryWarningSel = @selector(_performMemoryWarning);
if ([[UIApplication sharedApplication] respondsToSelector:memoryWarningSel]) {
[[UIApplication sharedApplication] performSelector:memoryWarningSel];
}else {
NSLog(@"%@",@"Whoops UIApplication no loger responds to -_performMemoryWarning");
}
#else
NSLog(@"%@",@"Warning: performFakeMemoryWarning called on a non debug build");
#endif
}
+1
source to share