フラグメントに 20 個の画像を動的に追加しています。ここでの問題は、フラグメントを破棄してリロードすると、破棄時にメモリが削除されず、20 枚の画像用に新しいメモリが追加されることです。
私のコードは次のとおりです。
for(int i=0;i<machImagesCursor.getCount();i++)
{
machImagesCursor.moveToPosition(i);
ImageView imageView=new ImageView(getActivity());
imageView.setId(i);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
100, 75);
imageView.setLayoutParams(layoutParams);
String imageName=machImagesCursor.getString(machImagesCursor.getColumnIndex("M_ImageName"));
String path = Environment.getExternalStorageDirectory().getPath()
+ "/fleetsyncimages/" +imageName ;
Log.d("image-path",path);
imageView.setImageURI(Uri.parse(path));
hScrollView.addView(imageView);
}
onDestroyで
for(int i=0;i<hScrollView.getChildCount();i++)
{
ImageView iv=(ImageView)hScrollView.getChildAt(0);
// iv.setImageBitmap(null);
Drawable d = iv.getDrawable();
((BitmapDrawable) d).getBitmap().recycle();
}
私のlogcatでは: ヒープは増え続けています。
前もって感謝します。