androidandroid-imageviewandroid-drawableandroid-bitmapandroid-memory

When 2 ImageViews are declared in xml layout then there are 2 copies of drawable in memory?


When I have an xml layout like:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/my_image" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/my_image" />

Then there are 2 instances of the bitmap associated with drawable in memory or just one?


Solution

  • You can find the answer here :

    For instance, every time you create a Button, a new drawable is loaded from the framework resources (android.R.drawable.btn_default). This means all buttons across all the apps use a different drawable instance as their background. However, all these drawables share a common state, called the "constant state."

    source: https://android-developers.googleblog.com/2009/05/drawable-mutations.html?m=1