#
Simulate memory warnings on the iPhone
When debugging on the simulator you can simulate a memory warning in your code by using the Simulate Memory Warning option in the Hardware menu. But on the device it isn’t so easy, but it’s really important to have thoroughly tested your application in the presence of memory warnings.
What I do is add some code to my App Delegate to periodically send a memory warning automatically. Usually every 5 seconds, or quicker.
- (BOOL)application:(UIApplication *)pApplication didFinishLaunchingWithOptions:(NSDictionary *)pLaunchOptions {
...
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(simulateMemoryWarning) userInfo:nil repeats:YES];
...
}
- (void)simulateMemoryWarning {
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidReceiveMemoryWarningNotification object:[UIApplication sharedApplication] userInfo:nil];
}
I suggest surrounding the timer scheduling with an #if DEBUG or similar (assuming you have DEBUG=1 configured in your debug builds) so you don’t accidentally leave this in for a release build!
This was posted 1 year ago. It has 0 notes.