Control the memory gained by my Android application

im trying to optimize the amount of memory consumed by my application. When my application loads (holding the home key and then selecting the task manager), I see that the application accepts 17 MB, but this value is not updated. How can I track this value in real time? Do DDMS have an option for this? Please be specific, I searched a lot and found nothing. thanks in advance

+6
source share
3 answers

Another code-based debugging method for tracking memory is displayed in fooobar.com/questions/893197 / ... with a link to a blog with more information.

To do this briefly, you can carefully place the following code (or an improved version) in some kind of click event and get real-time information in a log or message with a toast:

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); } }); 
+4
source

Yes, you can use DDMS, there is a guide here . Have a look in the section โ€œViewing heap usage for a processโ€

+3
source

Use eclipse memory analyzer

Here

After installing MAT. In the Eclipse IDE, from the Devices view, select your application and click "Dump HPROF File". It will automatically open a wizard for you to select which analysis you want to perform.

+2
source

Source: https://habr.com/ru/post/893196/


All Articles