我使用的是安卓 6.0。使用以下布局 LeakCanary 发现内存泄漏:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/background"/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Simple hint"
android:inputType="number|textNoSuggestions"
android:singleLine="true"
android:textSize="@dimen/title_text"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
没有EditText
内存泄漏。这是 LeakCanary 日志:
D/LeakCanary: * com.testapp.MainActivity has leaked:
D/LeakCanary: * GC ROOT static android.content.res.Resources.sPreloadedDrawables
D/LeakCanary: * references array android.util.LongSparseArray[].[0]
D/LeakCanary: * references android.util.LongSparseArray.mValues
D/LeakCanary: * references array java.lang.Object[].[2]
D/LeakCanary: * references android.graphics.drawable.InsetDrawable$InsetState.mDrawableState
D/LeakCanary: * references android.graphics.drawable.StateListDrawable$StateListState.mRes
D/LeakCanary: * references android.support.v7.widget.TintResources.mContext
D/LeakCanary: * leaks com.testapp.MainActivity instance
有没有人有同样的问题?如何解决?