I am writing a relatively small application. When it is launched, the heap size is 10 MB, allocated - 7-8 MB, but as you work with the program, the numbers run up to 50-60 MB. When running memory analizator message appears

One instance of "android.graphics.Bitmap" loaded by "" occupies 2,536,984 (21.22%) bytes. The memory is accumulated in one instance of "byte []" loaded by "".

instanceof Bitmap runs up to two hundred pieces. Does anyone know how this can be optimized?

  • Who knows. Maybe you are there uploading pictures of 2 megabytes. At first glance it seems unrealistic, and the pictures are loaded at 100kb, but you need to remember that they are unpacked into memory. 1280 by 800 with 32-bit color - that's almost 4 megabytes. And if it is just green, it will not weigh much (a couple of tens of kilobytes). - KoVadim
  • Yes, we do. But you need more information as you use them. - andreich
  • @bengal, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky

1 answer 1

The problem is known. When creating a bitmap from a file, you must create it using BitmapFactory . Try setting BitmapFactory.Options.inPurgeable=true - it helped me. When this flag is set, the bitmap will be unloaded from memory.

True, in KitKat and LolliPop this flag is declared deprecated , but there the machine is different, so the problem must be solved.