原型:
ActivityManagerService.java
public void getMemoryInfo(ActivityManager.MemoryInfo outInfo)
---------->Process.getFreeMemory() //Process.java
JNI实现 ------------->android_os_Process_getFreeMemory( ) //android_until_Process.cpp
---------------> open("/proc/meminfo", O_RDONLY);
可见其数据来源于/proc/meminfo文件,该文件包含了有关内存的许多不同类型的统计信息,这里只收集了其中两项的和。即MemFree + Cached
MemTotal: 995092 kB
MemFree: 412324 kB
Buffers: 67372 kB
Cached: 218692 kB
SwapCached: 0 kB
Active: 254272 kB
Inactive: 182248 kB
Active(anon): 150656 kB
Inactive(anon): 304 kB
Active(file): 103616 kB
Inactive(file): 181944 kB
Unevictable: 360 kB
Mlocked: 360 kB
HighTotal: 120836 kB
HighFree: 240 kB
LowTotal: 874256 kB
LowFree: 412084 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 4 kB
Writeback: 0 kB
AnonPages: 150856 kB
Mapped: 131816 kB
Shmem: 348 kB
Slab: 19168 kB
SReclaimable: 9248 kB
SUnreclaim: 9920 kB
KernelStack: 3432 kB
PageTables: 3316 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 497544 kB
Committed_AS: 2186448 kB
VmallocTotal: 122880 kB
VmallocUsed: 64980 kB
VmallocChunk: 18436 kB
DirectMap4k: 24568 kB
DirectMap4M: 884736 kB