2017-12-18 287 views
0

我有一个名为Test1的简单活动。启动其他活动时ImageView内存泄漏

这是布局代码。

<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

+0

'但是当我开始其他简单活动时?这是什么意思?你的意思是,你是从ImageView开始的第一项活动,然后从该活动开始另一项活动?你能详细说明一下吗? – Henry

+0

完成那个你写的onDestroy或者其他onDestroy()不会被调用的活动, – notTdar

回答

0

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

0

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