0

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 !

leonardkraemer
  • 6,573
  • 1
  • 31
  • 54
maniaq
  • 185
  • 1
  • 11

2 Answers2

1

Those are two different things.

Runtime.getRuntime().totalMemory()

returns the total amount of memory in the Java Virtual Machine. This value can change over time. This is the runtime free memory.

memInfo.totalMem

returns the total amount of available memory

You can consult these two SO topics:

Topic 1

Topic 2

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
0

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.

memInfo.totalMem is

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 one is the memory the jvm running your process holds, about 12 MB.
  • The second one is the total kernel accessible system memory, about one gigabyte in your case.

The first is part of the second.

Community
  • 1
  • 1
leonardkraemer
  • 6,573
  • 1
  • 31
  • 54