Allocation Instruments for iOS: compare memory of two snapshots - ios

In my situation I continuously enter one scene, than exit and so on... So Live bytes amount must be the same while reentering the scene, but it grows up by 3Mb on each enter.
I want to find memory that remains from previous scene. Memory Leak instrument shows no leaks.
How can I compare two "snapshots" of memory to highlight differences in allocations?
Previous scene snapshot:
After reentering:

approach it using Heapshot Analysis
Here's a great blog entry by bbum: When is a Leak not a Leak? Using Heapshot Analysis to Find Undesirable Memory Growth

Related

Xcode Memory Graph - showing increasing memory use - what exactly does it show?

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.

How to read Instruments Leaks graph?

I understand the Leaks tool takes a snapshot every X (default 10) seconds. But do the red bars in the Leaks graph tell me the amount of leaked memory at that snapshot in time? Or do they signify the cumulative memory leaked?
In other words, towards the end of this graph, has my app leaked the cumulative of all red bars in memory, or has it leaked no memory because the bar has diminished in size, and then didn't appear at all in the last snapshot interval?
You can check for yourself by clicking on the timeline and dragging over the time where the red bar is. A tooltip will open that tells you the number of leaks and the amount of leaked memory.
You'll find Instruments shows the cumulative total of leaks and leaked memory in the tooltip. In your screenshot, if you drag over the small red bar, the tooltip will report a higher number of leaks and leaked memory than it reports for the two taller bars in the graph.

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.

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.

Why are memory consumptions viewed from Activity Monitor and Instruments so different.

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

Resources