Why total memory extracted from getRuntime().totalMemory()
is not equal with when we use ActivityManager.MemoryInfo()
? In below two code part I get different values:
long totalMemory = Runtime.getRuntime().totalMemory() ;
and
ActivityManager actManager = (ActivityManager) getActivity().getSystemService(ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
long totalMemory = memInfo.totalMem
in first code I get 12.759.040 and from the second code I get 907.034.624 !
Runtime.getRuntime().totalMemory()
is
Returns the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.
The total memory accessible by the kernel. This is basically the RAM size of the device, not including below-kernel fixed allocations like DMA buffers, RAM for the baseband CPU, etc.
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.
The first is part of the second.