gpt4 book ai didi

java - Runime.getRuntime().totalMemory() 和 ActivityManager.MemoryInfo()

转载 作者:行者123 更新时间:2023-12-02 10:27:50 35 4
gpt4 key购买 nike

为什么从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!

最佳答案

这是两个不同的事情。

Runtime.getRuntime().totalMemory()

返回 Java 虚拟机中的内存总量。该值可能会随着时间而变化。这是运行时可用内存。

memInfo.totalMem

返回可用内存总量

您可以查阅这两个SO主题:

Topic 1

Topic 2

关于java - Runime.getRuntime().totalMemory() 和 ActivityManager.MemoryInfo(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53791529/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com