Reputation: 5960
Is there a way to do this? If so, how, and can it be done while running an app in the simulator and/or the real device?
Is there an alternative way to test response to memory warnings in Instruments?
Upvotes: 0
Views: 808
Reputation: 2200
You can simulate a memory warning while running the iPhone Simulator by going to the menu and selecting : Hardware > Simulate Memory Warning, which can be done at anytime even during running Instruments .
Upvotes: 1
Reputation: 69027
On the device, as far as I know, the only way to have a memory warning is actually creating a low memory condition. You can do that by allocating a big chunk of memory and freeing it after a few seconds (don't forget to release it, anyway). This may appear like a hack, but is the most reliable way of producing a low memory condition.
About the simulator, as you possibly know, using Instruments to check for memory/performance issues while running your app within the simulator is not entirely reliable. Anyway, if you would like to do that, you can try sending this notification:
- (void)simulateMemoryWarning
{
#if TARGET_IPHONE_SIMULATOR
#ifdef DEBUG
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"UISimulatedMemoryWarningNotification", NULL, NULL, true);
#endif
#endif
}
(Source)
Remember also that the simulator has got the "Hardware/Simulate Memory Warning" command.
Upvotes: 1