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?
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With