MaterialEditText icon indicating copy to clipboard operation
MaterialEditText copied to clipboard

Please fix the memory leak for custom fonts

Open ghost opened this issue 7 years ago • 2 comments

Here is my layout file:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background2"
    android:scrollbarStyle="outsideOverlay"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true">

        <RelativeLayout
            android:id="@+id/ActionBar"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@drawable/backlayer">

            <ImageButton
                android:id="@+id/backButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:background="@android:color/transparent"
                android:paddingStart="10dp"
                app:srcCompat="@drawable/ic_arrow_back_white_24dp" />

            <com.thebrownarrow.customfont.CustomFontTextView
                android:id="@+id/Title"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_centerVertical="true"
                android:gravity="center"
                android:text="Create an Account"
                android:textAlignment="center"
                android:textColor="#FFFFFF"
                android:textSize="25sp"
                app:custom_typeface="HelveticaNeue BlackCond.ttf" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@id/ActionBar"
            android:paddingEnd="20dp"
            android:paddingStart="20dp"
            android:paddingTop="20dp">

            <com.rengwuxian.materialedittext.MaterialEditText
                android:id="@+id/NameField"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Full Name"
                android:inputType="textPersonName"
                android:textSize="20sp"
                app:met_accentTypeface="Brandon_reg.otf"
                app:met_baseColor="@android:color/black"
                app:met_clearButton="true"
                app:met_floatingLabel="highlight"
                app:met_minBottomTextLines="1"
                app:met_primaryColor="?colorPrimaryDark"
                app:met_typeface="Brandon_reg.otf" />

            <com.rengwuxian.materialedittext.MaterialEditText
                android:id="@+id/EmailAddressField"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/NameField"
                android:hint="Email Address"
                android:inputType="textEmailAddress"
                android:textSize="20sp"
                app:met_accentTypeface="Brandon_reg.otf"
                app:met_baseColor="@android:color/black"
                app:met_clearButton="true"
                app:met_floatingLabel="highlight"
                app:met_minBottomTextLines="1"
                app:met_primaryColor="?colorPrimaryDark"
                app:met_typeface="Brandon_reg.otf" />

            <com.rengwuxian.materialedittext.MaterialEditText
                android:id="@+id/PasswordField"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/EmailAddressField"
                android:hint="Password"
                android:inputType="textPassword"
                android:textSize="20sp"
                app:met_accentTypeface="Brandon_reg.otf"
                app:met_baseColor="@android:color/black"
                app:met_clearButton="true"
                app:met_floatingLabel="highlight"
                app:met_minBottomTextLines="1"
                app:met_primaryColor="?colorPrimaryDark"
                app:met_typeface="Brandon_reg.otf" />

            <com.rengwuxian.materialedittext.MaterialEditText
                android:id="@+id/ConfirmPasswordField"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/PasswordField"
                android:hint="Confirm Password"
                android:inputType="textPassword"
                android:textSize="20sp"
                app:met_accentTypeface="Brandon_reg.otf"
                app:met_baseColor="@android:color/black"
                app:met_clearButton="true"
                app:met_floatingLabel="highlight"
                app:met_minBottomTextLines="1"
                app:met_primaryColor="?colorPrimaryDark"
                app:met_typeface="Brandon_reg.otf" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_below="@id/ConfirmPasswordField"
                android:background="@drawable/button1"
                android:text="Register"
                android:textColor="#FFFFFF" />
        </RelativeLayout>
    </RelativeLayout>
</ScrollView>

I ran into a post where they discussed about android custom font memory leak. I verified it and found that the memory leak exists for this library.

Brandon_reg.otf font is loaded 8 times in memory. Please fix this asap

C:\Users\Midhun\AppData\Local\Android\sdk\platform-tools>adb shell dumpsys meminfo com.eventinum.eventinum
Applications Memory Usage (kB):
Uptime: 83495948 Realtime: 154369572

** MEMINFO in pid 13129 [com.eventinum.eventinum] **
                   Pss  Private  Private  Swapped     Heap     Heap     Heap
                 Total    Dirty    Clean    Dirty     Size    Alloc     Free
                ------   ------   ------   ------   ------   ------   ------
  Native Heap        0        0        0        0    11520    10074     1445
  Dalvik Heap    28026    27868       44      548    44026    27767    16259
 Dalvik Other      569      568        0        0
        Stack      184      184        0        0
       Ashmem        2        0        0        0
    Other dev        5        0        4        0
     .so mmap      678       88      300     2172
    .apk mmap      286        0       56        0
    .ttf mmap       28        0       28        0
    .dex mmap     4212     4136       76        0
    .oat mmap     1693        0      820        0
    .art mmap     1590      976      400      180
   Other mmap       31        8       16        0
   EGL mtrack    10824    10824        0        0
      Unknown     6351     6296        8     2196
        TOTAL    54479    50948     1752     5096    55546    37841    17704

 App Summary
                       Pss(KB)
                        ------
           Java Heap:    29244
         Native Heap:        0
                Code:     5504
               Stack:      184
            Graphics:    10824
       Private Other:     6944
              System:     1779

               TOTAL:    54479      TOTAL SWAP (KB):     5096

 Objects
               Views:       19         ViewRootImpl:        1
         AppContexts:        2           Activities:        1
              Assets:       12        AssetManagers:        2
       Local Binders:        9        Proxy Binders:       19
       Parcel memory:        3         Parcel count:       13
    Death Recipients:        0      OpenSSL Sockets:        0

 SQL
         MEMORY_USED:        0
  PAGECACHE_OVERFLOW:        0          MALLOC_SIZE:        0


 Asset Allocations
    zip:/data/app/com.eventinum.eventinum-2/base.apk:/assets/HelveticaNeue BlackCond.ttf: 37K
    zip:/data/app/com.eventinum.eventinum-2/base.apk:/assets/Brandon_reg.otf: 85K
    zip:/data/app/com.eventinum.eventinum-2/base.apk:/assets/Brandon_reg.otf: 85K
    zip:/data/app/com.eventinum.eventinum-2/base.apk:/assets/Brandon_reg.otf: 85K
    zip:/data/app/com.eventinum.eventinum-2/base.apk:/assets/Brandon_reg.otf: 85K
    zip:/data/app/com.eventinum.eventinum-2/base.apk:/assets/Brandon_reg.otf: 85K
    zip:/data/app/com.eventinum.eventinum-2/base.apk:/assets/Brandon_reg.otf: 85K
    zip:/data/app/com.eventinum.eventinum-2/base.apk:/assets/Brandon_reg.otf: 85K
    zip:/data/app/com.eventinum.eventinum-2/base.apk:/assets/Brandon_reg.otf: 85K

ghost avatar Apr 07 '17 09:04 ghost

I found that this was previously added

https://github.com/rengwuxian/MaterialEditText/blob/75d084f4f2e65073ce1f20303ef29b26e11844ed/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java

But not present in the current release

ghost avatar Apr 07 '17 09:04 ghost

https://github.com/rengwuxian/MaterialEditText/pull/252/files

luckcoolla avatar Mar 21 '18 08:03 luckcoolla