5
我有A和B的活動。當我從活動A開始活動B時,我在活動B上設置了靜態位圖變量。我在屏幕上顯示該位圖並旋轉它。內存使用率不降低甚至我回收位圖
當活動B完成,我回收上的onDestroy()方法,但內存使用量沒有減少所有位圖。
@Override
protected void onDestroy() {
super.onDestroy();
if (bitmap90 != null) {
bitmap90.recycle();
bitmap90 = null;
}
if (bitmap180 != null) {
bitmap180.recycle();
bitmap180 = null;
}
if (bitmap270 != null) {
bitmap270.recycle();
bitmap270 = null;
}
if (mBitmap != null) {
mBitmap.recycle();
mBitmap = null;
}
if (((BitmapDrawable) ivOriginal.getDrawable()).getBitmap() != null) {
((BitmapDrawable) ivOriginal.getDrawable()).getBitmap().recycle();
ivOriginal.setImageDrawable(null);
}
if (((BitmapDrawable) ivOriginal90.getDrawable()).getBitmap() != null) {
((BitmapDrawable) ivOriginal90.getDrawable()).getBitmap().recycle();
ivOriginal90.setImageDrawable(null);
}
System.gc();
}
也許你在其他地方持有對你的位圖的引用。通常不鼓勵使用靜態屬性。你爲什麼不把你的位圖保存在一個文件中,然後在你的B活動中讀取它? –