The ListView
contains rather many items(20 or more), and each of them is an ImageView
with a bitmap source. These bitmaps are not compressed and have size about 640x480. When the ListView
is just loaded, it takes a few memory, but if I'll scroll it then the error "Memory exceed VM budjet"
may happen. When I replace the fragment with another fragment, the ListView
is still hanging in memory. How can I clear the ram/ListView cache?
Update :
I use a SimpleCursorAdapter
with a ViewBinder
:
SimpleCursorAdapter.ViewBinder viewBinder = new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (columnIndex == 0) {
TextView tv1 = (TextView) view;
if (cursor.getInt(4) == 0)
tv1.setTextColor(Color.GRAY);
else
tv1.setTextColor(Color.parseColor("#191919"));
tv1.setText(cursor.getString(columnIndex));
}
if (columnIndex == 3) {
TextView tv1 = (TextView) view;
tv1.setText(cursor.getString(columnIndex));
}
if (columnIndex == 2) {
final ImageView image = (ImageView) view;
Bitmap cachedImage = null;
try {
cachedImage = imageThreadLoader.loadImage(cursor.getString(columnIndex), new ImageThreadLoader.ImageLoadedListener() {
public void imageLoaded(Bitmap imageBitmap) {
image.setImageBitmap((Bitmap) new SoftReference(imageBitmap).get());
}
});
} catch (MalformedURLException mue) {
Log.e("Feeds fragment", "Can't load image");
}
if (cachedImage != null) {
image.setImageBitmap(cachedImage);
} else image.setImageDrawable(getResources().getDrawable(R.drawable.icon));
}
Images load in a separate thread.