android 如何log出 当前的程序使用的内存情况 或者说 Bitmap 使用了多大内存
android 怎么log出 当前的程序使用的内存情况 或者说 Bitmap 使用了多大内存
我想记录下Bitmap 图片 以不同方式打开所占的内存情况 那位大大 告诉小弟一下 不胜感激
怎么才能显示 当前的程序使用的内存情况
我试过的
1:
2:
3:
4:
我试过了 都不能得到当前程序 内存使用情况
我只想得到 某个变量 在内存中占了多大
------解决方案--------------------
从java里是得不到 内存的 要从so里
我想记录下Bitmap 图片 以不同方式打开所占的内存情况 那位大大 告诉小弟一下 不胜感激
怎么才能显示 当前的程序使用的内存情况
我试过的
1:
- Java code
System.out.println("获得整个程序的内存总数 ===== " + Runtime.getRuntime().totalMemory());
System.out.println("可用内存总数 ===== " + Runtime.getRuntime().freeMemory());
System.out.println("最大内存量 ===== " + Runtime.getRuntime().maxMemory());
2:
- Java code
public static void displayBriefMemory() {
Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576));
Double available = new Double(Debug.getNativeHeapSize())/1048576.0;
Double free = new Double(Debug.getNativeHeapFreeSize())/1048576.0;
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
df.setMinimumFractionDigits(2);
Log.d("gettings", "debug. =================================");
Log.d("gettings", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)");
Log.d("gettings", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)");
}
3:
- Java code
final ActivityManager activityManager = (ActivityManager) getSystemService(Service.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(info);
Log.e("####","系统剩余内存:"+(info.availMem >> 20)+"M");
Log.e("####","系统是否处于低内存运行:"+info.lowMemory);
Log.e("####","当系统剩余内存低于"+(info.threshold >> 20)+"M 时就看成低内存运行");
4:
- Java code
Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576));
Double available = new Double(Debug.getNativeHeapSize())/1048576.0;
Double free = new Double(Debug.getNativeHeapFreeSize())/1048576.0;
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
df.setMinimumFractionDigits(2);
Log.e("gettings", "debug. =================================");
Log.e("gettings", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)");
Log.e("gettings", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)");
我试过了 都不能得到当前程序 内存使用情况
我只想得到 某个变量 在内存中占了多大
------解决方案--------------------
从java里是得不到 内存的 要从so里