My answer would be as per Kirky Todds, but don't use applicationWillTerminate
-- it's not a good strategy on iOS4+ with multitasking, because this method often won't get called -- an app will be background, and then can be dumped from memory if other apps are run (or the phone is turned off/restarted), without applicationWillTerminate
getting called. (OR it will be foregrounded again. Either way, your cache doesn't get cleared.)
Instead, consider either clearing at startup (applicationDidFinishLaunching
), or in applicationWillEnterForeground
. The latter will tend to get called more frequently, because the former is only called on an actual proper app lauch (and not on a resume from being backgrounded).
For more info on backgrounding and the events generated, see:
http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/