Instruments: Heap Allocations and Anonymous VM

January 6th, 2014

Filed under: Instruments | 4 comments

One change to the Allocations instrument in Instruments 5, which comes with Xcode 5, is that the allocation summary lists the heap allocations and the amount of anonymous VM, which you can see in the following screenshot:

Instruments Anonymous VM

Should you focus on the Live Bytes column for heap allocations or anonymous VM? Focus on the heap allocations because your app has more control over heap allocations. Most of the memory allocations your app makes are heap allocations.

The VM in anonymous VM stands for virtual memory. When your app launches, the operating system reserves a block of virtual memory for your application. This block is usually much larger than the amount of memory your app needs. When your app allocates memory, the operating system allocates the memory from the block it reserved.

Remember the second sentence in the previous paragraph. The operating system determines the size of the virtual memory block, not your app. That’s why you should focus on the heap allocations instead of anonymous VM. Your app has no control over the size of the anonymous VM.

Facebooktwittergoogle_plusredditmail

Tags:


4 thoughts on “Instruments: Heap Allocations and Anonymous VM

  1. Alan Duncan says:

    Great observation – particularly when using heapshot (generation) analysis in Instruments to diagnose unexpected increases in memory utilization. Anonymous VM may climb and appear to be persistent across heapshots.

  2. Shrek says:

    My app appears so abnormal, the heap allocation occupied less than 20MB, but the anonymous VM occupied more than 300MB, then, it crashed, i want to know why,help me,thanks.
    http://www.cocoachina.com/ask/questions/show/117899

  3. Mark Szymczyk says:

    Shrek,

    I don’t know why your app crashed. As I said in the post, the operating system controls the size of the anonymous VM, not you, so there’s nothing I can tell you to do to reduce the size of the anonymous VM. I don’t know Chinese so I can’t read the question you linked to.

    If you want help, I recommend asking on Stack Overflow. You are going to have to provide more information than what you provided here for anyone on Stack Overflow to help you.

  4. Shrek says:

    Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *