Free up memory when asked to do so by the system.
If the system runs low on free memory and is unable to reclaim memory by terminating suspended apps, UIKit sends a low-memory warning to running apps. UIKit delivers low-memory warnings in the following ways:
It calls the
applicationmethod of your app delegate.
Did Receive Memory Warning:
It posts a
UIApplicationobject to any registered observers.
Did Receive Memory Warning Notification
It delivers a warning to dispatch queues of type
_SOURCE _TYPE _MEMORYPRESSURE
When your app receives a low-memory warning, free up as much memory as possible, as quickly as possible. Remove references to images, media files, or any large data files that already have an on-disk representation and can be reloaded later. Remove references to any temporary objects that you no longer need. If active tasks might consume significant amounts of memory, pause dispatch queues or restrict the number of simultaneous operations that your app performs.
To test your app’s response to a low-memory warning, use the Simulate Memory Warning command in iOS Simulator.