Reputation: 21815
If in my app I have non-critical data that is "global" to the app rather than specific to any particular view controller, are there any guidelines on where such data should be deallocated?
In particular: can I assume that on low memory, all view controllers will receive the didReceiveMemoryWarning event-- or at least, that the app's "initial" view controller will do-- and therefore just put the deallocation in once place? Or do I need to put it in all didReceiveMemoryWarning methods, because essentially any (but not necessarily all) of the view controllers' didReceiveMemoryWarning methods could be called?
Upvotes: 0
Views: 158
Reputation: 3993
All view controllers in the current window hierarchy will receive the automatic memory warning messages. Those not won't, but you can easily register a notification handler using UIApplicationDidReceiveMemoryWarningNotification
.
That said, it sounds like you have a singleton model object that you just want deallocated when memory gets low. You can register for that notification right in the singleton class, but the more correct design pattern would be for the ViewController to own the model (and thus, it couldn't be a global singleton), then that ViewController would be responsible for telling the model when to deallocate resources.
Upvotes: 2