Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitor the memory ocuppied by my app in Android

im attempting to optimize the amount of memory my app consumes. When my app loads (holding home key and then selecting task manager) i can see the app is taking 17MB but that value doesn't refresh. How can I track that value in real time? DDMS have a option for that? Please be specific I have searched a lot and nothing found. thanks in advance

like image 322
Caroline Avatar asked Jul 20 '11 18:07

Caroline


People also ask

How do I check app memory on Android?

Open your Apps list and tap the ""Settings"" app. Select ""Device care"" or ""Device maintenance"" on the menu—the name varies by model. Now, tap ""Memory"" to view the total amount of RAM in your phone or tablet, as well as RAM usage per app.

How much memory are my apps using?

Depending on your phone model, tap System > Memory or tap Memory in Settings to see how much memory is available and how your phone's memory is being used. You can also find out how individual apps are using memory. Tap Memory used by apps to find out the memory usage for apps.

Which app is consuming my RAM?

Tap “Memory” to see the RAM usage stats. You'll see the “Average Memory Use” at the top of the screen. Scroll down a bit further and select “Memory Used by Apps.” Here you'll see the RAM usage by apps.


1 Answers

Another more code-oriented debug method for memory tracking appears in https://stackoverflow.com/a/6471227/978329 with a link to a blog with more info.

To make it short, you can carefully put the following code (or an improved version of it) into some kind of on click event and get the real-time info into a log or a toast message:

View v = (View) findViewById(R.id.SomeLayout);

    v.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {

            Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
            Debug.getMemoryInfo(memoryInfo);

            String memMessage = String.format("App Memory: Pss=%.2f MB, Private=%.2f MB, Shared=%.2f MB",
                    memoryInfo.getTotalPss() / 1024.0,
                    memoryInfo.getTotalPrivateDirty() / 1024.0,
                    memoryInfo.getTotalSharedDirty() / 1024.0);

            Toast.makeText(ThisActivity.this,
                    memMessage,
                    Toast.LENGTH_LONG).show();
            Log.i("log_tag", memMessage);
        }
        });   
like image 132
wiztrail Avatar answered Sep 28 '22 00:09

wiztrail