a
554325746@qq.com
2020-01-13 7171bbcdb2859ea93f3af69d817243752b08314a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.basic.project.idcardservice;
 
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(Thread.currentThread().getId()+" " + "usedMB=" + usedMemInMB + " threadCount=" + Thread.getAllStackTraces().size()
                    + " availHeapMB=" + availHeapSizeInMB + " NativeHeapAllocated=" + getNativeHeapAllocatedSize
                    + " NativeHeap=" + getNativeHeapSize + " NativeHeapFree=" + getNativeHeapFreeSize
            );
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
}