Hi All i have strange memory leak with Bitmaps. First what i have - an
activity that based on the workspace view from Launcher ( 3 screens
current prev + next ) . This layout is supplied with adapter , so then
i flipping left/right it loads next view.
The views that adapter is providing is an ImageView (picture) with
decodeBitmap + TextView(Caption). I also have on click listener that
is set on the views that toggles captions which calls this:
public void onToggleCaption() {
mAdapter.toggleCaption(); // sets boolean if is should display
caption
int currentScreen = mImageLayout.getCurrentScreen(); //
remembers
current screen number.
mImageLayout.removeAllViews(); // Removes all three children
mImageLayout.setCurrentScreen(currentScreen); // Set back
everything
back ( but now adapter will show or hide captions )
}
When i call this from the menu - everything is just fine. Heap stays
same +/- 1K. If i execute this code via onClick listener - i'm loosing
memory quite quickly and in about 20th iteration - VM out of budget.
adapter. public View getView(int position, View convertView, ViewGroup
parent) {
View newView = null;
byte[] mFullImage;
Enclosure enclosure = (Enclosure) getItem(position);
if (convertView != null)
newView = convertView;
else {
LayoutInflater layout = LayoutInflater.from(mContext);
newView = layout.inflate(R.layout.image_layout, null);
}
//TODO - this can be optimized
ImageView iView = (ImageView) newView.findViewById(R.id.image);
TextView tView = (TextView) newView.findViewById(R.id.caption);
Bitmap image = null;
// mFullImage is a byte[]
mFullImage = enclosure.getImage();
if (mFullImage != null) {
try {
image =
BitmapFactory.decodeByteArray(mFullImage, 0,
mFullImage.length);
} catch (RuntimeException e) {
Log.w(TAG, e);
}
}
if (image != null) {
iView.setImageBitmap(image);
String caption = enclosure.getContent();
if (!caption.equals("") && mShowCaption) {
tView.setVisibility(View.VISIBLE);
tView.setText(caption);
} else {
tView.setVisibility(View.GONE);
}
}
newView.setClickable(true);
return newView;
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---