Determine how much memory allocated for individual objects? - ios

I can't find how to determine how much memory is in use by individual objects.
Using Xcode's visual memory debugger, the memory shown on the right side (circled red) is not how much memory the object is actually using.
Xcode allocation instruments seems to only show the entire heap and memory used by individual allocations, not objects as a whole.
Am I missing something? Is there anyway to see how much aggregated memory is used by individual objects?

Related

How do I determine which threads are taking up memory in my iOS app - information from Instruments is limited?

My application has many different components - an AR view, a separate SceneKit view, UI, and underlying algorithms which are ongoing.
I want to determine which area could be causing performance issues. Here's what Xcode gives me, under CPU:
These threads all appear to be re-sized so that they fill the height of their graph. So it's not useful to determine what's actually taking up resources.
And here's what Instruments gives me, under Time Profiler:
Here I can clearly see that some threads dominate, but it's impossible to identify any of these threads.

iOS Instrumentation: how to interpret Memory Allocations Template?

I am using Allocations Profiling template for an iOS Instrumentation.
I created an extension to UIView class, that takes a snapshot for a view that is not added to the view hierarchy. I want to double check how much memory does my new method consume.
I have found out that my new method allocates 288 Bytes from the heap as indicated in the following image.
Then I navigated to the corresponding method and I found out that there is a big memory amount as expected. Have a look on the following image.
My questions are:
Why could not I see these huge number in the heap?
Where is this huge memory allocated from?
Is there a specific detail view (other than Call Tree) that reflects this hug number?
Please note that I am not asking about what is the best way to take a snapshot for a view. I am already familiar with Apple method snapshotView. I am doing this exercise just to test my understanding for the Memory Usage in iOS.
A couple of thoughts:
Be careful when filtering the results of the call tree. You could have accidentally pruned out the routine with which the profiler associated the memory. Try (a) selecting the range of the graph that has the allocation in question (to reduce the amount of noise in the results); (b) removing the filter and then (c) expand the tree at that point where you see the large memory jump:
Personally, I often find it easier to flip the call tree and hide system libraries:
Alternatively, you can also go to the "Statistics" of "Allocations" and find the big allocation:
You can then drill into that:
And then by clicking on the "Extended Detail" panel on the right, jump to the code in question:
If you want, another way to find allocations in Xcode 8 is to turn on the "Malloc Stack" option on your scheme and then use the "Debug Memory Graph" option as outlined in https://stackoverflow.com/a/30993476/1271826.
For example, I used the "Debug Memory Graph", found the CG Raster Data, and I can see the object graph for this 10mb image, as well as can see the stack where this was allocated in the "Extended Details" panel on the right:

Memory keeps growing but no leaks reported

I have an app that's very memory intensive...LOTS of image processing in Core Graphics routines and custom pixel processing routines.
I've been very careful with memory as far as I can tell, but the longer my app runs, I notice memory slowing rising in the Memory Report in Xcode 5. I've run it many times in Instruments and I don't see any leaks.
Any ideas on how to debug this or where I can look?
Thanks.
You can use instruments to see what is getting allocated and to look at the retain/release/autorelease lifecycle of an image and what the call stack is for each of them.
If you have memory growing without leaks you are still holding onto the memory somewhere.

iOS Instruments Allocations Net/Overall

I have been tested my app with instruments allocations and get this picture:
Like graphic shows, my app work normally, but is it normally value in overall bytes? And I'm worry about "#Allocations (Net/Overall)", because it's color is red.What is it mean (red color)
Red is the total (Overall) allocations made and deallocated during all your App's runtime.
Purple (really thin bar over the red one) are the allocated and not yet deallocated objects.
I would say that you don't need to worry too much about it, specially for internal objects or Malloc, and focus indeed on higher level objects such as views and controllers.
Also if you click on the Allocations tool's i you can choose to ignore CF (Core Foundation) or Malloc allocations, which I often do as you don't normally deal directly/don't have control over those allocations.
Again as you improve your higher level objects allocations you'll be indirectly improving those underlying allocations as well.

Unreasonable Heap Growth

Hi I have truble with allocated memory, because I noticed in Instruments a lot of Heap Growth, so I designed a test app.
Test app contained two ViewControllers and each have one button.
First ViewController was linked thru Segue Modal to SecondViewController (and it has NO code at all - beside auto-generated).
Second ViewController has only function
-(IBAction)back:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
so I could flip throw views.
When I test it whit Instrument I noticed heap growth after I go to second view and back.
How is that posible? What am I missing?
The size of the heap is not the app memory usage.
When your app is alive, the kernel will have to allocate memory for you.
Modern systems uses virtual memory. Basically, they map physical addresses to virtual addresses, that your process will access.
This mapping is handled by the kernel, and it needs memory for it.
If you request 1MB of memory, it will have to allocate memory to keep track of the physical pages allocated, by increasing the size of your adress space.
If you free all memory, the kernel will usually keep the memory used for the mapping, and re-use it for the next allocations, avoiding the need to reallocate space for it.
This is why the heap size doesn't change. But it does not indicate your application's memory usage at all.
If using Instruments, look at the VM Tracker tool for this.

Resources