Tip: Low Memory Warnings

Hey, here’s a handy tip for scheduling low memory warnings for your debugging pleasure: use AppleScript!

LOW MEMORY WARNING BOMBARDMENT TOOL

I wanted to share a tool that I use in as part of checking an app for behaving correctly under low memory warnings, to the extent that is possible to do so using the Simulator. It’s an Applescript that just sends a low memory warning to the simulator every second or so, so you can go through every function of your app while debugging and see if a low memory warning ever causes a crash…

It’s simply triggering the ‘Simulate Memory Warning’ menu item repeatedly for you … but hey, there’s been times that we wanted to simulate low memory conditions whilst in the midst of an action that required our full attention, and it never occurred to us to whip up a script like this…

h/t: @politepix!

UPDATE:

Note in the comments that there’s an unofficial API call “_performMemoryWarning” you can use for the same purpose in code:

[NSTimer scheduledTimerWithTimeInterval:1.0 target:[UIApplication sharedApplication] selector:@selector(_performMemoryWarning) userInfo:nil repeats:YES];

That will work nicely on the device no doubt. Just don’t forget to remove it before submitting!

Alex | April 26, 2011
  • Stephan Burlot April 27, 2011 at 3:37 pm
    You can also use this code in your app: [NSTimer scheduledTimerWithTimeInterval:1.0 target:[UIApplication sharedApplication] selector:@selector(_performMemoryWarning) userInfo:nil repeats:YES]; This tricks was shown to me by Nicolas Seriot (@nst021) and is an invaluable tool to crash-proof your apps. Don't leave this code in your published app!
  • Alex April 27, 2011 at 4:46 pm
    Hey, even better trick. Thanks Stephan!

Leave a Reply