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:
...
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)
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.
The "Memory usage" logs here are displayed with my logMemoryUsage() function which is based on code from this answer.
For the record, I'm using SDWebImage 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...
Why is iOS terminating my app, even though I'm responding to memory warnings by happily freeing a ton of memory?