I have a question because couldn't find anything relative in android documentations.
When I run an simple app (a generic project from Android studio or a google example app) in Android Studio I check the initial native memory. Lets say its 17 mb. If I change orientation couple of times, then the native memory will go to 40mb and if I force a GC the memory will drop to 23-25. If I do this a couple of times, after the GC the memory will stay at 23-25. So where do those extra MB come from?
There is no memory leak of course, because I checked it and because the native memory would kept rising.
Does android keep some sort of cache?
Also if in app I use libraries e.x retrofit2, glide e.t.c the native memory will increased but within a limit +20mb from the initial native memory.
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)");
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.