Hi, here's some code i threw together for simulating memory warnings in your app, so you can be sure you're handling them well.

It only affects the simulator, so in production you'll be just the same. This uses method swizzling to extend your view controllers, so that every time a viewWillAppear is called, it simulates a memory warning. And you don't need to change your view controllers' base class or anything, so this file is easy to drop in (and out of) a pre-existing project for the duration of your memory usage/leak testing.

Many thanks to cocoawithlove and idevrecipes for most of the below code, I just combined it all to work together so you don't need to change your view controllers at all. Simply create a 'MemoryWarnings.m' file in your project and paste the below code in it:

Thanks for reading! And if you want to get in touch, I'd love to hear from you: chris.hulbert at gmail.

Chris Hulbert

(Comp Sci, Hons - UTS)

iOS Developer (Freelancer / Contractor) in Australia.

I have worked at places such as Google, Cochlear, Assembly Payments, News Corp, Fox Sports, NineMSN, FetchTV, Coles, Woolworths, Trust Bank, and Westpac, among others. If you're looking for help developing an iOS app, drop me a line!

Get in touch:
[email protected]
github.com/chrishulbert
linkedin
my resume



 Subscribe via RSS