Inflatable performance evokes 40MHz bump in memory

I am doing some debugging and finally came to a specific line that makes my application use 4x RAM. This is the line in my snippet:

 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
     View v = inflater.inflate(R.layout.comments, container, false);
     return v;
 }

      

The R.layout.comments view shows the following:

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
    android:id="@+id/back"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:clipToPadding="false"
    android:minHeight="60dp"

    android:orientation="horizontal"
    android:paddingTop="60dp"
    android:weightSum="100" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:layout_below="@+id/back">


    <RelativeLayout
        android:id="@+id/menu"
        android:layout_width="match_parent"
        android:layout_height="120dp"

        >


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="120dp">

            <LinearLayout
                android:id="@+id/colorsbg"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_alignParentTop="true"
                android:clipToPadding="false"

                android:elevation="8dp"
                android:minHeight="60dp"
                android:orientation="horizontal"
                android:weightSum="100">

                <TextView
                    android:id="@+id/totalupvotes"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:text="4022"
                    android:textColor="#fff"

                    android:textSize="22sp"
                    android:textStyle="bold" />

                <ImageView
                    android:id="@+id/save"
                    android:layout_width="0dp"
                    android:layout_height="60dp"
                    android:layout_weight="25"
                    android:background="@drawable/starbackgroundbig"

                    android:gravity="center"
                    android:padding="13dp"
                    android:scaleType="fitCenter"
                    android:src="@drawable/staricon"

                    />

                <ImageView
                    android:id="@+id/upvote"
                    android:layout_width="0dp"
                    android:layout_height="60dp"
                    android:layout_weight="25"
                    android:background="@drawable/upvotebackgroundbig"
                    android:gravity="center"
                    android:padding="13dp"
                    android:scaleType="fitCenter"
                    android:src="@drawable/upvoteicon"

                    />

                <ImageView
                    android:id="@+id/downvote"
                    android:layout_width="0dp"
                    android:layout_height="60dp"
                    android:layout_weight="25"
                    android:background="@drawable/downvotebackgroundbig"
                    android:gravity="center"
                    android:padding="13dp"

                    android:scaleType="fitCenter"
                    android:src="@drawable/downvoteicon"

                    />
            </LinearLayout>

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/layoutright"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_alignParentBottom="true"
                android:orientation="vertical"

                android:paddingBottom="0dp"


                android:paddingStart="20dp"

                android:scrollbars="none">

                <TextView
                    android:id="@+id/title"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:gravity="center_vertical"
                    android:text="Loading replies..."
                    android:textColor="#fff"

                    android:textSize="20sp"
                    android:textStyle="bold">

                </TextView>

            </LinearLayout>

            <LinearLayout
                android:id="@+id/subscribebg"
                android:layout_width="wrap_content"
                android:layout_height="60dp"

                android:layout_alignParentBottom="true"
                android:layout_alignParentEnd="true"
                android:layout_gravity="center"
                android:gravity="center"
                android:orientation="vertical"
                android:paddingBottom="0dp"
                android:paddingEnd="20dp"
                android:scrollbars="none">


                <ToggleButton
                    android:id="@+id/toggleama"
                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"
                    android:background="#00000000"
                    android:textAlignment="center"
                    android:textOff="ENABLE AMA MODE"
                    android:textOn="DISABLE AMA MODE" />
            </LinearLayout>
        </RelativeLayout>


    </RelativeLayout>


    <ListView
        android:id="@+id/commentsList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"


        android:background="#ff141414"
        android:orientation="vertical" />

    <com.melnykov.fab.FloatingActionButton xmlns:fab="http://schemas.android.com/apk/res-auto"
        android:id="@+id/commentreply"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"

        android:layout_alignParentEnd="true"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:gravity="bottom|end"
        android:scaleType="fitCenter"


        android:src="@drawable/reply"
        fab:fab_colorNormal="#E64A19"
        fab:fab_colorPressed="#ffb94018"
        fab:fab_colorRipple="#ffb23717" />

</RelativeLayout>


<ProgressBar
    android:id="@+id/progressloading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"

    android:indeterminate="true" />

      

What would make this look use up so much memory? Am I not fanning it?

EDIT: Here are the XML files for downvotebackgroundbig, ect.

<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/clearbg" />
<item android:drawable="@drawable/redbig" />
</transition>

      

and redbig

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#F34235" />
</shape>

      

+3


source to share


2 answers


I had the same problem. In my cases, the image loading issue caused the issue. How big are the images you are using in the layout?



+1


source


You are inflating the view the way you should, but your view contains ImageView

. Images take up a lot of memory, much more than disk / storage. This is because the image is compressed while it is on disk (saved in JPG, PNG, or similar format). Once the image is loaded into memory, it is no longer compressed and takes up as much memory as needed for all pixels (usually width * height * 4 for RGBA_8888 or width * height * 2 for RGB_565). My bet is that this is the reason for the increased memory usage.



+1


source







All Articles