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

问题描述 投票:0回答:2

我有一个名为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

android xml android-layout
2个回答
0
投票

为了处理图像,我建议你使用像GlidePicasso这样的库,他们会为你处理一切。 (内存泄漏,缓存等)


0
投票

不确定你的意思是“开始其他简单的活动”,但如果你要去应用程序中的另一个活动,那么你的当前活动(使用imageview)应该暂停而不是销毁。当你去另一个活动时调用finish()或者只是在onPause()方法中放入onDestroy()代码

© www.soinside.com 2019 - 2024. All rights reserved.