Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're getting low memory warnings and fail to release enough memory to resolve the issue, your app will almost certainly crash. The thing is, I don't think that the particulars of how or why it crashed can possibly be illuminating. At that point, you're evaluating secondary symptoms. You really need to go back and figure out <em>why</em> you got the low memory warning in the first place and fix that problem.</p> <p>As Daniel said, you can look at <a href="http://developer.apple.com/library/ios/technotes/tn2151/_index.html#//apple_ref/doc/uid/DTS40008184-CH1-UNDERSTANDING_LOW_MEMORY_REPORTS" rel="nofollow noreferrer">Technical Note 2151</a>, but as it says:</p> <blockquote> <p>When you see a low memory crash, rather than be concerned about what part of your code was executing at the time of termination, you should investigate your memory usage patterns and your responses to low memory warnings. <a href="https://developer.apple.com/library/ios/#recipes/instruments_help-memory-allocations-help/Eliminating_Messages_To_Deallocated_Objects/06_Eliminating_Messages_To_Deallocated_Objects.html#//apple_ref/doc/uid/TP40011396-CH4-SW1" rel="nofollow noreferrer">Memory Allocations Help</a> lists detailed steps on how to use the Leaks Instrument to discover memory leaks, and how to use the Allocations Instrument's Mark Heap feature to avoid abandoned memory. <a href="https://developer.apple.com/library/mac/#documentation/Performance/Conceptual/ManagingMemory/ManagingMemory.html#//apple_ref/doc/uid/10000160i" rel="nofollow noreferrer">Memory Usage Performance Guidelines</a> discusses the proper ways to respond to low-memory notifications as well as many tips for using memory effectively. It is also recommended that you check out the WWDC 2010 session, <a href="https://developer.apple.com/videos/wwdc/2010/?id=311" rel="nofollow noreferrer">Advanced Memory Analysis with Instruments</a>.</p> </blockquote> <p>So, a couple of thoughts:</p> <ol> <li><p>Have you looked for leaks? The <a href="https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/MemoryManagementforYouriOSApp/MemoryManagementforYouriOSApp.html#//apple_ref/doc/uid/TP40004652-CH11-SW4" rel="nofollow noreferrer">Finding Leaks</a> article walks you through how to use instruments to find your leaks.</p></li> <li><p>If you turned on zombies, have you turned them off? Zombies is a great diagnostic tool, but just consumes memory.</p></li> <li><p>Have you run your code through the static analyzer (<kbd>shift</kbd>+<kbd>command</kbd>+<kbd>B</kbd> or select "Analyze" on the "Product" menu)? Especially if using non-ARC code, this can find lots of memory issues.</p></li> <li><p>Have you examined your allocations for unexplained increases without offsetting decreases with the Instrument's <code>Allocations</code> tool. Using that, you can run the program, look at the consumption of memory on the graph and see if you see any increases that aren't offset at some point by the corresponding decreases. And if so, highlight those increases in the graph:</p> <p>For example, when running the Allocations tool, hold down the option key and then click-and-drag with your mouse to highlight a portion of the timeline, to identify what you want to inspect. You probably want to focus on one of your spikes in allocations. For example, I found a bump in my allocations and highlighted it as such (this was a ludicrously simple example where I create a huge array in <code>viewDidLoad</code>, but hopefully it give you the idea):</p> <p><img src="https://i.stack.imgur.com/xXqwI.png" alt="allocations"></p> <p>Note, I find it useful to show the call tree in the lower panel, it's often useful to select "Hide System Libraries", to focus on your code (and "Invert Call Tree", too). And if you double click on the method name in Instruments (in my example, here, it would be viewDidLoad), Instruments will then show you your code that's doing the allocation:</p> <p><img src="https://i.stack.imgur.com/4W24i.png" alt="show code"></p></li> </ol>
 

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