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.
Related
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?
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:
When watching the debug graph in xcode 6 (and probably 5 too), when running my application the memory use continues to rise as I place more of a certain object on the screen and animate it's movement. It does not seem to decrease when I remove it. Once removed I believe there are no more references to them.
See screenshot:
http://i.stack.imgur.com/SnhbK.png
However when I use Instruments to try to identify what's going on, there's only around 12mb persisting, and Total Bytes continues to rise, as expected.
See screenshot:
http://i.stack.imgur.com/VBwce.png
Is this normal behaviour? What exactly is the graph in Xcode showing? Am I overlooking something?
In Instruments I have Allocation Lifespan set to All Allocations and Allocation Type set to All Heap and Anonymous VM for the screenshots above.
UPDATE
By running Instruments with Activity Monitor I was able to see that the "Real Memory" was increasing at the same rate as is displayed in Xcode. #Mark Szymczyk pointed out that OpenGL ES Texture memory allocations are not shown in the Allocations instrument.
By purging the texture cache with the following command in Cocos2D 3.1 at regular intervals, memory use consistently drops back down to around 18mb and begins increasing again as I add more sprites.
[[CCDirector sharedDirector] purgeCachedData];
Credits go to Mark Szymczyk for pointing me in this direction - thanks!
Looking at your screenshots, the Xcode graph is probably showing the equivalent of the Total Bytes column in your Instruments screenshot. When you remove an object, the persistent bytes will decrease, but the total bytes won't. That would explain why the memory use never goes down in the Xcode graph.
The Persistent Bytes column in Instruments is what you should be looking at to determine your app's memory usage.
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.
My app is a music player, it plays MP3's continuously from internet with AV Foundation. It has memory consumption issues.
When I look for the reason with Allocations or Leaks instruments, the Activity Monitor reports memory consumptions of 50MB or so.
When I run the app with Product->Run, the Activity Monitor reports memory consumptions of 20MB initially, and it increases 100kB per second. Why are they so different?
Further more, the Allocations or Leaks instruments all have the 'Allocations' row. The right side bars in Allocations gradually turn into red. The right side bars in Leaks are always blue. The 'Allocations' row works differently in these two instruments? I use Xcode 4.1.
To answer the question in the last paragraph, the Allocations instrument is configured differently for the Allocations and Leaks templates. In the Allocations template, the instrument tracks all memory allocations. In the Leaks template the instrument tracks only active allocations. The histogram (the colored bar on the right side) reflects the ratio of active to total allocations, with blue indicating a high ratio and red indicating a low ratio. Because the Leaks instrument tracks only active allocations, the active allocations equal the total allocations, giving you a blue histogram. Click the Info button next to the Allocations instrument to configure what it records.
If you want to see how much memory your application is using, look at the Live Bytes column for the All Allocations category in the Allocations instrument. Also, take a look at the following question:
Xcode Instruments output interpretation for iPad app