package com.basic.security.utils;
|
|
import android.os.Debug;
|
|
import com.basic.security.base.BaseApplication;
|
|
public class MemoryUtil {
|
|
public static void monitorMemory() {
|
if (1 == 1) {
|
return;
|
}
|
try {
|
Runtime runtime = Runtime.getRuntime();
|
long usedMemInMB = (runtime.totalMemory() - runtime.freeMemory()) / 1048576L;
|
long maxHeapSizeInMB = runtime.maxMemory() / 1048576L;
|
long availHeapSizeInMB = maxHeapSizeInMB - usedMemInMB;
|
if ((availHeapSizeInMB * 1.0) / (maxHeapSizeInMB * 1.0) < 0.1) {
|
AppUtil.restartApp(BaseApplication.getApplication());
|
}
|
long getNativeHeapAllocatedSize = Debug.getNativeHeapAllocatedSize() / 1048576L;
|
long getNativeHeapSize = Debug.getNativeHeapSize() / 1048576L;
|
long getNativeHeapFreeSize = Debug.getNativeHeapFreeSize() / 1048576L;
|
System.out.println(" " + "usedInMB=" + usedMemInMB + " " + Thread.getAllStackTraces().size()
|
+ " availHeapSizeInMB=" + availHeapSizeInMB + " getNativeHeapAllocatedSize=" + getNativeHeapAllocatedSize
|
+ " getNativeHeapSize=" + getNativeHeapSize + " getNativeHeapFreeSize=" + getNativeHeapFreeSize
|
);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
}
|