views:

141

answers:

3

I have used /proc/meminfo and parsed command response.however it result shows that :

MemTotal: 94348 kB MemFree: 5784 kB

means. it shows there is only 5MB free memory. Is it possible with android mobile? There is only 5-6 application installed on my mobile and no other task is running. but still this command shows there is very less free memory.

Can somebody clarify this? or is there any other way of getting memory usage in android?

A: 

Linux's memory management philosophy is "Free memory is wasted memory".

I assume that the next two lines will show how much memory is in "Buffers" and how much is "Cached". While there is a difference between the two (please don't ask what that difference is :) they both roughly add up to the amount of memory used to cache file data and metadata.

A far more useful guide to free memory on a Linux system is the free(1) command; on my desktop, it reports information like this:

$ free -m
             total       used       free     shared    buffers     cached
Mem:          5980       1055       4924          0         91        374
-/+ buffers/cache:        589       5391
Swap:         6347          0       6347

The +/- buffers/cache: line is the magic line, it reports that I've really got around 589 megs of actively required process memory, and around 5391 megs of 'free' memory, in the sense that the 91+374 megabytes of buffers/cached memory can be thrown away if the memory could be more profitably used elsewhere.

(My machine has been up for about three hours, doing nearly nothing but stackoverflow, which is why I have so much free memory.)

If Android doesn't ship with free(1), you can do the math yourself with the /proc/meminfo file; I just like the free(1) output format. :)

sarnold
A: 

Another way (currently showing 25MB free on my G1):

MemoryInfo mi = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
long availableMegs = mi.availMem / 1048576L;
alex
Hey Alex,Thanks a lot for your help !1 more question. This code gives me available RAM. I also want to display Total RAM. How to get that?
Badal
@Badal I don't know a Java API for that. Stick to parsing /proc/meminfo.
alex
+1  A: 

Hi Alex...Thank you. Its done and it works !

Let me tell you what I did, So others who visit this thread can come to know the steps:

  1. parse /proc/meminfo command. You can find reference code here: http://stackoverflow.com/questions/3118234/how-to-get-memory-usage-and-cpu-usage-in-android

  2. use below code and get current RAM:

.

MemoryInfo mi = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
long availableMegs = mi.availMem / 1048576L;
  1. please note that - we need to calculate total memory only once. so call point 1 only once in your code and then after, you can call code of point 2 repetitively.
Badal