启动其他活动时ImageView内存泄漏

时间:2017-12-18 02:42:21

标签: android xml android-layout

我有一个名为Test1的简单活动。

这是布局代码。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/test"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ImageView
        android:id="@+id/imageview1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:src="@drawable/load"
        android:scaleType="fitXY" />

</RelativeLayout>

在我的onDestory方法中,我发布了mImageView资源,在Android配置文件中,mImageView的内存实际上已被回收。

    @Override
    protected void onDestroy() {
        super.onDestroy();
        releaseImageViewResource(mImageView);
        layout.removeView(mImageView);
        mImageView.setVisibility(View.GONE);
        mImageView.setImageDrawable(null);
        mImageView = null;
    }

enter image description here
但是当我开始其他简单活动时,mImageView的内存无法回收。为什么以及如何解决问题? enter image description here

2 个答案:

答案 0 :(得分:0)

为了处理图片,我建议您使用GlidePicasso等库,他们会为您处理一切。 (内存泄漏,缓存等)

答案 1 :(得分:0)

Not sure what you mean by "start other simple activity", but if you are going to another activity within the application, then your current activity (with the imageview) should be paused instead of destroyed. Either call finish() when you go to the other activity or just put that onDestroy() code in the onPause() method

相关问题