2017-12-18 258 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()代碼