Caroline
Caroline

Reputation: 61

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

Upvotes: 6

Views: 3872

Answers (3)

wiztrail
wiztrail

Reputation: 3988

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);
        }
        });   

Upvotes: 4

softarn
softarn

Reputation: 5496

Yes you can use the DDMS, there is a guide here. Look under "Viewing heap usage for a process"

Upvotes: 3

Sharique Abdullah
Sharique Abdullah

Reputation: 655

Use eclipse memory analyzer

Here

After installing MAT. In your eclipse IDE, from the Devices view select your application and click Dump HPROF file. It would automatically open a wizard for you to select what kind of analysis do you want to perform.

Upvotes: 2

Related Questions