Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does android reuse images loaded from resource?

So I have several ImageViews in a single Activity and all of them use the same image bitmap from a resource.

ImageViewOne.setImageResource(R.drawable.frequently_used_image);
ImageViewTwo.setImageResource(R.drawable.frequently_used_image);
ImageViewThree.setImageResource(R.drawable.frequently_used_image);

Does android allocate memory to load the bitmap once and reuse it for all other ImageViews using the same resource? Or does it load the bitmap each time it is set to an ImageView?

Thanks!

like image 872
baekacaek Avatar asked Jun 13 '13 23:06

baekacaek


1 Answers

Quoting Dianne Hackborn from Android team:

Also keep in mind that Resources already maintains a cache of Drawables for you, using this facility, so there is no need for you to implement your own cache for any Drawables you are retrieving from Resources.

from this answer: Consequences of drawable.setCallback(null);

like image 105
MaciejGórski Avatar answered Nov 01 '22 17:11

MaciejGórski