轉載至:https://juejin.cn/post/7098257692828893220
Java代碼獲取內存信息:
private void getMaxMemoryInfo() {
Runtime rt = Runtime.getRuntime();
long maxMemory = rt.maxMemory();
Log.e("XMemory", "Dalvik MaxMemory:" + Long.toString(maxMemory / (1024 * 1024)));
ActivityManager activityManager = (ActivityManager) ContextHolder.getAppContext().getSystemService(Context.ACTIVITY_SERVICE);
Log.e("XMemory", "Dalvik MemoryClass:" + Long.toString(activityManager.getMemoryClass()));
Log.e("XMemory", "Dalvik LargeMemoryClass:" + Long.toString(activityManager.getLargeMemoryClass()));
ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(info);
Log.e("XMemory", "系統(tǒng)總內存:" + (info.totalMem / (1024 * 1024)) + "M");
Log.e("XMemory", "系統(tǒng)剩余內存:" + (info.availMem / (1024 * 1024)) + "M");
Log.e("XMemory", "系統(tǒng)是否處于低內存運行:" + info.lowMemory);
Log.e("XMemory", "系統(tǒng)剩余內存低于" + (info.threshold / (1024 * 1024)) + "M時為低內存運行");
}

通過名命令行獲取內存信息:
