XCode Instruments Allocations: Look at Live Bytes or Overall Bytes? - ios

I am getting some memory warning in my iOS app so I am running Instruments to see the allocations. Should I look at the * All Allocations * Live Bytes or Overall Bytes?
Someone said the iOS can close my app if I use for 22MB, is that from the Live or Overall bytes section?

Live Bytes is the current usage and is what you are interested in, overall bytes includes all released allocation. The other thing is to look at the graph and look for peaks. As an example I saw a huge peak of about 27MB in an app I was working on, knowing that I was able to reduce peak memory usage to 8MB.
Also watch over time as you exercise your app, it is possible to have substantial memory growth over time that is not leaked, just not not used anymore.
For a description of the memory columns see Explanation of Live Bytes & Overall Bytes.

Related

My app is slow, how to read this Xcode instrument

Users are complaining that my app is slow sometimes, so I did allocations profile, check attached image below, Live bytes is around 35 MB.
Is 35 MB fine or I have to lower it?
What's the best Live bytes?
I see ImageIO_PNG_Data & JS garbage collector have the biggest allocation.
How can I clear them?
Thanks
P.S. I'm using ARC
You're looking in the wrong place. To determine why your application is slow, you will need to use one of the CPU instruments (e.g, Time Profiler), not memory allocation.

Xcode Instruments Allocations Overall Bytes Too Large

I have completed my first iOS app. Its parsing and an rss feed and showing titles, date, creator name and images in a tableview. Now i am trying to check its performance before submitting it for the approval. I am using Xcode instruments for the very first time. I have first checked and removed all the leaks and now there are no memory leaks in the app. Now i am using Allocations. Here is how it looks like:
Since i am using it for the very first time i am not sure about many things. Overall Bytes looks too large to me and i need to ask whether is there any limit or not which i can use? and should i look for overall bytes or live bytes or anything else?
Thanks
Overall bytes includes those that have been released and is a running total of what has been allocated to your app during the lifetime of the app. The Live Bytes is the one to really worry about as that is the one that shows bytes that are currently allocated.
Overall bytes could keep going on forever as long as you release stuff and the Live Bytes doesn't go too high then you will have no problems.
From that screenshot live bytes looks ok.
There are more details here XCode Instruments Allocations: Look at Live Bytes or Overall Bytes?

What's the right statistic for iOS Memory footprint. Live Bytes? Real Memory? Other?

I'm definitely confused on this point.
I have an iPad application that shows 'Live Bytes' usage of 6-12mb in the object allocation instrument. If I pull up the memory monitor or activity monitor, the 'Real Memory' Column consistently climbs to around 80-90mb after some serious usage.
So do I have a normal memory footprint or a high one?
This answer and this answer claim you should watch 'Live Bytes' as the 'Real Memory' column shows memory blocks that have been released, but the OS hasn't yet reclaimed it.
On the other hand, this answer claims you need to pay attention to that memory monitor, as the 'Live Bytes' doesn't include things like interface elements.
What is the deal with iOS memory footprint!? :)
Those are simply two different metrics for measuring memory use. Which one is the "right" one depends on what question you're trying to answer.
In a nutshell, the difference between "live bytes" and "real memory" is the difference between the amount of memory currently used for stuff that your app has created and the total amount of physical memory currently attributed to your app. There are at least two reasons that those are different:
code: Your app's code has to be loaded into memory, of course, and the virtual memory system surely attributes that to your app even though it's not memory that your app allocated.
memory pools: Most allocators work by maintaining one or more pools of memory from which they can carve off pieces for individual objects or allocated memory blocks. Most implementations of malloc work that way, and I expect that the object allocator does too. These pools aren't automatically resized downward when an object is deallocated -- the memory is just marked 'free' in the pool, but the whole pool will still be attributed to your app.
There may be other ways that memory is attributed to your app without being directly allocated by your code, too.
So, what are you trying to learn about your application? If you're trying to figure out why your app crashed due to low memory, look at both "live bytes" (to see what your app is using now) and "real memory" (to see how much memory the VM system says your app is using). If you're trying to improve your app's memory performance, looking at "live bytes" or "live objects" is more likely to help, since that's the memory that you can do something about.
Seeing as how I wrote the last answer you linked to, I'll have to stand by that. If you want a total, accurate count of the current memory usage for your application, use the Memory Monitor instrument.
For reasons that I describe in this answer, Allocations hides the memory sizes of certain elements, meaning that its memory usage totals are significantly lower than your application's in-memory size. Many people find this out the hard way when they try to get their application functional on older iOS devices. On the older hardware, you had a hard memory ceiling of ~30 MB, where if you exceeded that your application was hard-killed.
Many developers (myself included) saw that we only had ~1-2 MB of live bytes in Allocations and thought we were good, until our applications started receiving memory warnings and early terminations. If you looked at Memory Monitor, you could see the true in-memory size of these applications being >20 MB, and you could see the applications being terminated the instant they crossed the 30 MB barrier in Memory Monitor.
Therefore, if you want an accurate assessment of your total application memory usage, use Memory Monitor. Allocations is great to find out the specific objects that are in memory, particularly when you use the heap shots to find things that might be accumulating (as leaks, retain cycles, or for other reasons). Just don't trust it when determining your application's actual size in memory.
'Live bytes' means memory allocated by your code (for example by malloc), so you have access to this memory. 'Real memory' shows physical amount of memory used by your app. This include also OpenGL textures, (possibly) sounds from Open AL...
Live bytes is useful to check when you allocate and release memory in your code. Real memory is good indicator for memory optimization efficiency. And it's overhead causes 'low memory' warnings.

Checking iOS application used memory in instruments

I want to make sure I'm reading the allocations plug in correctly. I'm testing an iPad app thats receiving memory warnings 1,2 & 3.
I want to know the current used up memory from my app, which I think it has to be the "Live Bytes" column? which marks All Allocations to 2.42 MB which I think its low.
What do the other columns report? #Transitory, Overall Bytes ?
Also if my app uses only 3 MB of memory can it be killed if I get a memory level 3 warning without releasing?
Thank you.
Don't use the Object Allocations instrument for looking at your total memory usage. It does not display the true total memory size of your application, for reasons that I speculate about in my answer here.
Instead, pair Object Allocations with the Memory Monitor instrument, the latter of which will show the true total size of your application. I'm willing to bet that it's way larger than the 2.42 MB you're seeing in Object Allocations (for example, I had an application with 700k of memory usage according to ObjectAlloc, but its actual size was ~25 MB in memory). If you are receiving memory warnings on an iPad, your application is probably chewing up quite a bit of memory.
Object Allocations is handy for telling you what you have resident in memory, but it's not an accurate indicator of the size of those items. It's also a great tool for showing you steady increases in allocated objects by using the heap shot functionality (the "Mark Heap" button on the left-hand side of the instrument).
Your memory usage looks fine. Check to see which app is being sent the memory warnings, it is probably not your app assuming your app is not in the background. The only way you should be getting memory warnings is if the app is in the background and another app needs more memory.
When I was looking at logs I noticed other apps were getting them while my app was running, other apps such as Mail or navigation apps (Navigon) do run in the background and will cause memory pressure. You might get a memory warning but should not be terminated.
For a description of the memory columns see Explanation of Live Bytes & Overall Bytes.
As #Brad points out use the memory monitor tool as well.

Analyzing Instruments readings

Leaks:
None
ObjectAlloc:
Net Bytes: 4,332,512
# Net: 26,696
Overall Bytes: 103,769,552
# Overall: 738,987
Activity Monitor (MyApp):
# Thread: 6
Real Memory: 63.65 MB
Virtual Memory: 209.45 MB
Memory monitor showed same readings as Activity Monitor. I don't know whether these readings are good or bad. Memory indicated by Activity Monitor is horrifying. Should i be worried? Can i somehow estimate memory used by the application once its moved to the device. The real run time memory? Thanks.
Memory usage as reported by Object Allocation is not very autoritative, at least according to my experience. The real deal is the real memory consumption as reported by Memory Monitor, see my question on iPhone memory consumption. Your numbers seem to be measured in Simulator, such measurement is worthless. You have to measure on the device.
Object Alloc is reporting to the total memory used over the entire lifespan of the run. That means if objects are allocated and deallocated (which they often are) you see all the memory consumed in total.
Far more useful is to select the option "created and still living", then highlight regions of the graph where memory increases but it never goes down if you expect it would. Then you can see how much memory is being allocated at that point and what is allocating it. This works in the simulator as well as the device.

Resources