Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE</strong> As of iOS 6, <code>UIViewController</code> views are no longer unloaded in response to memory warnings. Instead just do your best to release any resources you can reasonably re-create (e.g. cached data) when <code>didReceiveMemoryWarning</code> is called. </p> <p><strong>UPDATE</strong><br> I wrote my original answer when I was an angry young man; times have changed and basically, it's wrong.</p> <p>If you have an app with a single view controller and you receive a memory warning, there's not much you can do. But things change dramatically if you have multiple view controllers, because you can unload <strong>all</strong> the state associated with the non frontmost controllers. In fact <code>[UIViewController didReceiveMemoryWarning]</code> will prod you in the right direction by unloading your non-visible views for you (surprise!). When the frontmost view controller is dismissed, the underlying view is reloaded and at most the user should only be aware of a delay even though internally your app may have done a complete reboot.</p> <p>This is not some detail you can easily retrofit, you need to keep memory usage in mind from the beginning and design your multiview app into cleanly unloadable <code>UIViewController</code> pieces. In fact it's worth keeping your code compatible with the simulator just to use its memory warning feature. </p> <p>When memory is abundant, nothing is unloaded and everything is silky smooth, and when memory is low things keep working, albeit more slowly. Now I'd say that this solution to the finite memory problem is ideal.</p> <p>To take advantage of this memory parlour trick, overload the <code>UIViewController</code> methods <code>viewDidLoad</code>,<code>viewDidUnload</code>, and <code>viewWillUnload</code> (iOS5, useful if unloading state requires your view to still exist, e.g. if you don't want to leak your OpenGL textures &amp; render buffer, on iOS4 you can simulate this by overloading <code>didReceiveMemoryWarning</code> and tracking your view's visibility). </p> <p><strong>ORIGINAL, MORE BILIOUS ANSWER</strong></p> <p><code>didReceiveMemoryWarning</code> is absolutely useless. </p> <p>There's no guarantee that if you free up memory (even all of it) that you won't get killed.</p> <p>In my bitter experience it usually works like this on 2.x/3.0:</p> <ol> <li><p>mediaserverd leaks a bunch of memory</p></li> <li><p>my app gets killed</p></li> </ol> <p>Unfortunately, the reaper never thinks of killing mediaserverd.</p> <p>So if the memory usage isn't your fault, you've really only got two choices: </p> <ol> <li><p>ask the user to reboot (user assumes it's your fault, writes a scathing review)</p></li> <li><p>hope the culprit crashes (mediaserverd often obliges!)</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload