Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test if your iOS app behaves well on memory warnings?

I recently noticed that sometimes our app crashes right after receiving a memory warning. It's very hard to reproduce this problem on device, and even in simulator I get this crash in maybe one of ten attempts to “Simulate Memory Warning”.

What is a good strategy to debug memory warning handlers, considering issues often come from callbacks arriving “too late”, resources accidentally used after being destroyed in warning handler, etc?

like image 822
Dan Abramov Avatar asked Jan 22 '13 22:01

Dan Abramov


1 Answers

Here's an approach that helped me find several severe bugs in my memory warning handlers.

First, I went to OS X Keyboard settings and assigned a shortcut to Simulate Memory Warning:

enter image description here

Then, when running the app in simulator, I kept these buttons pressed, so the Simulator would generate tens of memory warnings per second. While doing that, I would go around the app. Of course this is rarely what happens in the real world, but this stress-testing helped reveal some synchronization, callback and state issues, which I wouldn't have found otherwise.

like image 184
Dan Abramov Avatar answered Oct 11 '22 17:10

Dan Abramov