Programatically get free and used RAM in ios

Hi,

I need to programatically compute the free and used RAM in ios using objective C. Most of the samples I have seen uses host_statistics API, although that works but that API is macOS specific and not iOS. I am looking for API which is compliant with iOS.

Answered by DTS Engineer in 742467022

Is host_statistics officially supported by Apple?

The question as to what’s “officially supported” depends on the context. Two common contexts are:

  • App Review. Will they approve an app that uses this API?

  • DTS. Will DTS answer questions about it.

I work for DTS, not App Review, and thus can only give you definitive answers about the latter (which is “Yes” btw). My understanding is that App Review host_statistics as API because it’s in the iOS SDK, but you’d have to talk with them to get a definitive answer.

The reason I am asking is because the official documentation says macOS 10.0+ and no other OS.

I presume you’re talking about this page. If so, you’re being confused by a quirk in our documentation.

host_statistics, like much of Mach, is both API (Application Programming Interfaces) and KPI (Kernel Programming Interfaces). If you look at the context of that page, you’ll see that it lives within the so-called Kernel framework. KPI only makes sense in the context of KEXTs (kernel extensions) and those are only supported on macOS. Hence this page is flagged as macOS-only.

However, this has no bearing on the API story. Our official documentation does not cover low-level APIs (r. 18030527), that is, APIs from the Mach and BSD layers. That’s why there’s no official documentation for printf )-: These APIs are documented elsewhere:

  • For BSD, that’d be the the man pages. For more on this, see Reading UNIX Manual Pages.

  • For Mach, well, there’s no great documentation on that front. The best docs available are those embedded within the Darwin kernel source, like this page.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

host_statistics is available on iOS.

Having said that, the whole concept of “free memory” is essentilly meaningless on Apple platforms. See On Free Memory.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Is host_statistics officially supported by Apple? The reason I am asking is because the official documentation says macOS 10.0+ and no other OS.

Accepted Answer

Is host_statistics officially supported by Apple?

The question as to what’s “officially supported” depends on the context. Two common contexts are:

  • App Review. Will they approve an app that uses this API?

  • DTS. Will DTS answer questions about it.

I work for DTS, not App Review, and thus can only give you definitive answers about the latter (which is “Yes” btw). My understanding is that App Review host_statistics as API because it’s in the iOS SDK, but you’d have to talk with them to get a definitive answer.

The reason I am asking is because the official documentation says macOS 10.0+ and no other OS.

I presume you’re talking about this page. If so, you’re being confused by a quirk in our documentation.

host_statistics, like much of Mach, is both API (Application Programming Interfaces) and KPI (Kernel Programming Interfaces). If you look at the context of that page, you’ll see that it lives within the so-called Kernel framework. KPI only makes sense in the context of KEXTs (kernel extensions) and those are only supported on macOS. Hence this page is flagged as macOS-only.

However, this has no bearing on the API story. Our official documentation does not cover low-level APIs (r. 18030527), that is, APIs from the Mach and BSD layers. That’s why there’s no official documentation for printf )-: These APIs are documented elsewhere:

  • For BSD, that’d be the the man pages. For more on this, see Reading UNIX Manual Pages.

  • For Mach, well, there’s no great documentation on that front. The best docs available are those embedded within the Darwin kernel source, like this page.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Programatically get free and used RAM in ios
 
 
Q