title: Why does iOS terminate my app even when I free lots of memory in response to memory warnings?
body: <p>I can't figure out why iOS is terminating my app (iPad, iOS 4) due to memory usage even after I free a ton of memory in response to low-memory warnings. For example, here's a typical termination scenario, with me logging memory usage every so often -- look at the "app" usage, the first KB value on each line:</p>
  
  <pre><code>...
  2011-12-14 13:25:42.343 Oyster[211:707] Memory usage (KB): app 268256, delta 6472, used 366800/373940
  2011-12-14 13:25:43.292 Oyster[211:707] Memory usage (KB): app 273900, delta 5644, used 372444/381024
  2011-12-14 13:25:44.159 Oyster[211:707] Memory usage (KB): app 282920, delta 9020, used 381464/389116
  2011-12-14 13:25:45.184 Oyster[211:707] Memory usage (KB): app 272140, delta -10780, used 370684/379432
  2011-12-14 13:25:46.109 Oyster[211:707] Memory usage (KB): app 260412, delta -11728, used 358956/365900
  2011-12-14 13:25:48.443 Oyster[211:707] Received memory warning. Level=2
  2011-12-14 13:25:48.454 Oyster[211:707] Memory usage (KB): app 9172, delta -251240, used 107716/112548
  (gdb)
  </code></pre>
  
  <p>You can see app memory usage increasing till it gets a memory warning. Then I correctly respond to the memory warning and free a bunch (250MB!) of memory. At that point my app is terminated and iOS goes to the iPad home screen.</p>
  
  <p>The "Memory usage" logs here are displayed with my <a href="http://pastebin.com/JWQEY4s9" rel="nofollow noreferrer">logMemoryUsage() function</a> which is based on code from <a href="https://stackoverflow.com/questions/2798638/available-memory-for-iphone-os-app">this answer</a>.</p>
  
  <p>For the record, I'm using <a href="https://github.com/rs/SDWebImage" rel="nofollow noreferrer">SDWebImage</a> to cache UIImages in memory, but as shown, it handles memory warnings by emptying its cache (rather large at this point). I realize I could tweak SDWebImage's caching to not fill all available memory and just wait for memory warnings, but that begs the following question...</p>
  
  <p><strong>Why is iOS terminating my app, even though I'm responding to memory warnings by happily freeing a ton of memory?</strong></p>