Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "Anonymous VM" in allocations instruments signify?

I get frequent memory warnings in my application but I don't know why. Here is the snapshot of allocation instruments.

Instruments

I know that we don't have any control over virtual memory assigned to us but I am trying to understand what information does that number 26.50 MB means for a developer.

 1. What does a high VM means ? Does it lead to a jetsam ? Is that cause of any other concern ?
 2. Is this value dependent on device ?
 3. Does a low vm means that your app is memory efficient 
 4. Does a high VM leads to memory warnings in your app ?
 5. What cause this value to change ? 
 6. What steps should a developer take when they see a high vm for their app (like 300 MB) ? 
 7. Is VM tracker instrument related to this value ?

like image 745
Kunal Balani Avatar asked May 18 '15 15:05

Kunal Balani


People also ask

How do you use allocation instruments?

Instrumenting AllocationsPress Command-I in Xcode, select Allocations from the list and press Choose. After a moment, you'll see the Allocations instrument. It should look familiar because it looks a lot like Time Profiler. Click the record button in the top-left corner to run the app.

What are instruments in Xcode?

Instruments is a powerful performance analysis and testing tool that's part of Xcode toolset. Instruments can help you profile your apps on all platforms - iOS, macOS, watchOS, tvOS - in order to better understand and optimize their behavior and performance.

What is profiler in Swift?

In simplest of terms, Time Profiler collects information about your app while it's running, determines how long each of your functions takes to run, and also figures out the percentage of CPU cycles each of your functions is using.


1 Answers

Anonymous VM covers a lot of things, some of which are things you want to minimize and some that are generally less important. The short version of "anonymous VM" is that it's addresses you have mapped but not named. Heap allocations get "named" which lets you track them as objects. But there are lots (and lots) of non-objecty things that fall into the "anonymous VM" bucket.

Things allocated with malloc can wind up in this region. But also memory mapped files. Your executable is a memory mapped file, but since it's never dirty, parts of it can be swapped out. So "it's complicated." But in big, vague terms, yes, you do care about this section, but you may not care about all of it very much. Heap allocations tends to track your ObjC stuff. Anonymous VM often tracks things that you don't have a lot of direct control over (like CALayer backing storage).

All that said, the Instruments output you provide doesn't look like any major problem. I suspect it's not indicative of a time you're pressuring memory. You'll need to get yourself into a memory warning situation and see what's going on then, and dig into the specifics of what is using memory.

For much more detail on this, you should watch WWDC 2013 session 704 "Building Efficient OS X Apps" which goes into depth on much of this. While iOS has a somewhat different memory system, and some OS X tools aren't available on iOS, many of the concepts still apply.

like image 165
Rob Napier Avatar answered Oct 06 '22 18:10

Rob Napier