IOS Low Memory Alerts and Simulator Memory Alerts

IOS apps receive low memory warnings through these mechanisms:

  • [AppDelegate applicationDidReceiveMemoryWarning:]

  • UIApplicationDidReceiveMemoryWarningNotification

  • [UIViewController didReceiveMemoryWarning]

What is the relationship between these elements? Do they all occur when a low memory state is received, or are there subtle differences? In what order are they executed?

The simulator has an option "Simulate memory warnings". Does this do anything other than callable didReceiveMemoryWarning:

on all UIViewControllers?

I want to use Xcode's profiler tool to see what's going on these days around cached images [UIImage imageNamed:]

- are they not cached? - but I need to know how to "properly" run low memory conditions, even if it just allocates a whole bunch of memory.

+3


source to share


2 answers


In response to your question about the cache UIImage

for imageNamed

yes, it looks like it clears the cache. Here I loaded 225 images through imageNamed

, and then, 20 seconds before execution, I simulated a memory warning:

allocations for imageNamed

Having said that, I think the cache imageNamed

is a dumb tool, and I prefer to make my own cache through NSCache

, so I can limit how many images it should keep in the cache by setting countLimit

, in order to prevent memory warnings altogether. As an aside, while NSCache

not responding UIApplicationDidReceiveMemoryWarningNotification

, it automatically cleans up in real low memory situations. However, it will not respond to manually simulating the memory warning in the simulator.



Anyway, here is a log of loading images with NSCache

, first without countLimit

, and secondly with countLimit

out of 50, clearing the cache at the end of each one:

NSCache without and with countLimit

+3


source


Partial answer:

I have confirmed that on the simulator (iOS6.1 on iOS Simulator 6.0) "Simulating Memory Alert" triggers all three mechanisms to start in the following order:



  • [AppDelegate applicationDidReceiveMemoryWarning:

  • [UIViewController didReceiveMemoryWarning]

  • UIApplicationDidReceiveMemoryWarningNotification

0


source







All Articles