本机内存增加

时间:2018-10-24 10:36:33

标签: android heap-size

我有一个问题,因为在android文档中找不到任何相对的东西。

当我在Android Studio中运行一个简单的应用程序(来自Android Studio或Google示例应用程序的通用项目)时,我会检查初始本机内存。可以说它的17 MB。如果我几次改变方向,则本机内存将达到40mb,如果我强制使用GC,则内存将降至23-25。如果我多次这样做,则GC后内存将保持在23-25。那么那些多余的MB是从哪里来的呢?

当然没有内存泄漏,因为我检查了一下,因为本机内存会不断增加。

  

android是否保留某种缓存?

如果在应用程序中我使用的是e.x retrofit2库,则在e.t.c滑行中,本机内存将增加,但要比初始本机内存增加20mb以内。

LogHeap:

 Log.d("tag", "debug. =================================");
                Log.d("tag", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)");
                Log.d("tag", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory() / 1048576.0)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory() / 1048576.0)) + "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory() / 1048576.0)) + "MB free)");

1 个答案:

答案 0 :(得分:0)

Disclaimer: the following is true for a normal JVM, I don't know for sure if Android behaves the same way.

Classes (the byte code) are loaded on demand, but never unloaded. So when your app starts you probably don't have all the classes loaded yet, just the bare minimum necessary to start. The more the app is used, the more classes will get loaded until you have them all.