Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCODE instruments Allocation Growth

Allocation Graph

I am running uiautomation scripts on an ios application. After about 40 iterations of:

logging in tapping several buttons over and over and then logging out

i arrive at this graph.

My question is regarding the allocations graph. Is it supposed to look like that? My script stopped running and i think its because of too many memory leaks? I know where the leaks are and it is in the same place all the time. But over time should the allocations graph look like this? I'd assume that in an ideal memory conscious application that it would essentially maintain a 0 slope. But what this means to me is that over time there is still alot allocated?

Question: is the graph supposed to look like this? With the steps i am doing if memory is being released correctly (non-arc) should it maintain a sloped allocation graph/over time?

like image 209
Rohan Panchal Avatar asked Mar 23 '23 09:03

Rohan Panchal


1 Answers

No, the graph should not look like this. Allocations generally should fall back down (except for caches, and even those should fall back down when purged on memory pressure).

There's no point in worrying about allocations, though, until you fix the leak(s). That might do it. Fix the leak and repeat the above exercise and see if allocations are flat. If not, then you might have other issues. But fixing the leak might remedy the situation entirely.

Also, if you haven't already, run the tool through the static analyzer ("Analyze" on the Xcode "Product" menu or press shift+command+B). Especially in MRC code, that will identify many routine memory management issues. It's like magic. Make sure you get a clean bill of health there before you proceed.

Then use the Leaks tool to pin point precise what's leaking. Then you can diagnose why that particular object is leaking. Fix that leak before proceeding. See the Finding Leaks section of the Instruments User's Guide.

Once you've done all of that you can repeat the process of your original question, and see if allocations continue to grow (e.g. such as might be caused by a retain cycle). If you're still having problems after fixing the leaks as identified above, there are techniques in instruments to identify the type of incremental allocations, which you can then use to track down any further issues, if any.

For example:

  • Run Allocations tool, option-click and drag in the allocations tool, and you can then look at the call tree and it will show you what's consuming memory. See this answer for an example.

  • Run the Allocations tool. Let the app settle down to a point of quiescence. Click on the "Mark heap" button. Do bunch of stuff. Return back to the point where you think that stuff should have been released. Press "Mark heap" again. Now look at that heap snapshot and look at the objects that were allocated but not released between the two snapshots, and again you should be able to diagnose what's going on.

But all of this is moot until you fix the leak and the Leaks tool will pin point the leaked object more effectively than anything else. Fix that first, and then see where you stand.

For more information, you might find some of the discussion in WWDC 2012 iOS App Performance: Memory video useful (especially in the demonstration sections).

like image 192
Rob Avatar answered Apr 01 '23 01:04

Rob