Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory warning level in applicationDidReceiveMemoryWarning

Tags:

iphone

ipad

As far as I know there are 2 levels of memory warnings. applicationDidReceiveMemoryWarning doesn't come with the warning level. Is there a way to get this information?

like image 349
user309305 Avatar asked Dec 16 '22 22:12

user309305


1 Answers

It's not that there are two levels of warning--not in terms of, like, "you have a little memory left" and then "you have less memory left". It's that the same "low memory" warning gets fired two places. Once on the UIViewController subclass currently in view (and, if that UIVC doesn't implement didReceiveMemoryWarning, then it'll bubble up to the top of the view controller stack) and again on the Application Delegate in applicationDidReceiveMemoryWarning. One's not a "worse" warning than the other, they're just two different hooks for implementing a response to the same warning from the OS.

It's one of the quirks of the platform that you can't really know how much memory you'll have available at any time. Background apps (mail, phone, etc) suck as much RAM as they need, and you're left to get the rest, and the only way you can know you've gotten too big is when the OS says so.

It's important to respond appropriately, by ditching resources you don't need right now. Start with the low-hanging fruit--anything big you're keeping around for later. Images, for instance, that you can ditch and then pull from a server or from disk later when you need them again.

like image 130
Dan Ray Avatar answered Apr 19 '23 23:04

Dan Ray