Using Android Application Memory for Android

What is the difference between the Allocated usage that we can see in the Elipse Memory Analysis Tool (in the DDMS view) and the memory usage size for the same application shown here on an Android device ?:

SettingsApplicationsWork

Despite the fact that I aggressively tried to save memory by making the objects zero as soon as they were not needed, the last number (the size of the memory usage on the "Launch Applications" screen) only increased, and my application finally crashed due to OutOfMemoryError. However, the first showed me that I was in reasonable size. I also often called System.gc (). Is there a difference between the two? Why the discrepancy? Any ideas on how I can solve this problem?

+4
source share
2 answers

The biggest difference between the two that I know of is the amount of garbage collected.

Regular garbage collection, including System.gc() , collects some garbage and then stops. This is not full heap coverage to get rid of everything. That is, try to minimize the impact of the CPU on garbage collection.

A heap dump prepared for MAT, however, is effectively a full GC.

Your symptoms indicate that you are allocating memory faster than the GC can recover it. The main solution for this is to try to allocate less memory or allocate it less often. For example, where possible, reusing objects, bitmap buffers, etc., instead of trying to let the GC clear old stuff and highlight new things along the way.

+2
source

It looks like you have a memory leak somewhere in your application if the memory is never released. This means that somewhere you maintain a strong reference to a large object that is recreated (e.g. Activity or Bitmap), so calling System.gc () does not matter.

I suggest looking at the following in memory management in android from google IO 2011. This allows you to learn how to use the eclipse memory analysis tool, which is incredibly useful for debugging these kinds of errors.

0
source

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


All Articles