java - In Android, how to find the total used memory (native and non-native) in bytes for my app programmatically? -


although there similar questions (such a), answers not solve problem.

i using android studio 1.5.1 targeting android api 18 (before android kitkat 4.4, i’m dealing dalvik, not art runtime).

my question is:

in android, how find total used memory (native , non-native) in bytes used app programmatically without using native code?

update:

why other similar solutions not solve problem?

here problem in more details:

i have 2 methods, before() , after(). bothe methods have same code calculate total used memory method after() has integer local variable

int consume = 123;

the problem after() method should show total used memory + 4 (which size of int variable consume), instead of both give me same total used memory.

not sure why other answers didn't solve problem, doing @ same api level.

public static void getmemorystat(){      double max = runtime.getruntime().maxmemory();      double heapsize = runtime.getruntime().totalmemory();      double heapremaining = runtime.getruntime().freememory();      double nativeusage = debug.getnativeheapallocatedsize();       double totalmemoryused = (runtime.getruntime().totalmemory() + android.os.debug.getnativeheapallocatedsize());     int percentused = (int)(totalmemoryused / runtime.getruntime().maxmemory() * 100);     double remaining = max - (heapsize - heapremaining + nativeusage);      errorlog.log("max:"+ max);     errorlog.log("heapsize:"+ heapsize);     errorlog.log("heapremaining:"+ heapremaining);     errorlog.log("nativeusage:"+ nativeusage);     errorlog.log("remaining:"+ remaining);     errorlog.log("percentused:"+ percentused);  } 

errorlog custom class. should change log.d()


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -