为什么从getRuntime().totalMemory()中提取的总内存与使用ActivityManager.MemoryInfo()时不相等?在下面两个代码部分中,我得到了不同的值:
long totalMemory = Runtime.getRuntime().totalMemory() ;和
ActivityManager actManager = (ActivityManager) getActivity().getSystemService(ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
long totalMemory = memInfo.totalMem在第一个代码中,我得到12.759.040,从第二个代码中,我得到907.034.624!
发布于 2018-12-15 10:47:08
Runtime.getRuntime().totalMemory()是
返回Java虚拟机中的总内存量。此方法返回的值可能随时间而变化,这取决于主机环境。
内核可访问的总内存。这基本上就是设备的RAM大小,不包括内核以下的固定分配,比如DMA缓冲区、基带CPU的RAM等等。 请注意,容纳任何给定类型的对象所需的内存量可能与实现有关。
第一个是第二个的一部分。
https://stackoverflow.com/questions/53791529
复制相似问题