我想记录下Bitmap 图片 以不同方式打开所占的内存情况 那位大大 告诉小弟一下 不胜感激怎么才能显示 当前的程序使用的内存情况我试过的
1:
System.out.println("获得整个程序的内存总数 ===== " + Runtime.getRuntime().totalMemory());
System.out.println("可用内存总数 ===== " + Runtime.getRuntime().freeMemory());
System.out.println("最大内存量 ===== " + Runtime.getRuntime().maxMemory()); 2: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: 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: 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)");我试过了 都不能得到当前程序 内存使用情况我只想得到 某个变量 在内存中占了多大
1:
System.out.println("获得整个程序的内存总数 ===== " + Runtime.getRuntime().totalMemory());
System.out.println("可用内存总数 ===== " + Runtime.getRuntime().freeMemory());
System.out.println("最大内存量 ===== " + Runtime.getRuntime().maxMemory()); 2: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: 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: 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)");我试过了 都不能得到当前程序 内存使用情况我只想得到 某个变量 在内存中占了多大
String str1 = "/proc/meminfo";
String str2;
Double memory = 0.0;
try {
FileReader r = new FileReader(str1);
BufferedReader bufferedRead = new BufferedReader(r, 8192);
str2 = bufferedRead.readLine();
System.err.println("str2--------->" + str2);
String str4 = str2.substring(str2.length() - 9, str2.length() - 3);
memory = Double.parseDouble(str4) / 1000; } catch (Exception e) {
// TODO: handle exception
} return memory; }看看能不能帮到你