android - ArrayList of Drawable or ArrayList of Bitmap? -
i getting 1 scenario have store images in arraylist
(bitmap
or drawable
). when bitmaps come mind think memory issues outofmemory
. arraylist
of drawable
make difference? or arraylist
of bitmap
? should use?
this interesting question ... generalizing answer don't know why need use list
of drawable
/bitmap
.
to honest wouldn't use neither of them because:
- bitmaps: these objects occupy lot of memory , storing these in memory can harmful sure sooner or later if you're not careful. example: maybe send list through
intent
different component. if , initial list not destroyed you'll case have doubled amount of memory bitmaps deserialized new objects on target component side. - drawables:
bitmapdrawable
keeps reference bitmap, don't see provide benefit on bitmap itself. may "forget" clear list ofdrawables
, way you've memory leaked bitmaps. don't think creatingdrawable
time consuming or resource consuming make worth caching.
to add more, have cover cases activity destroyed, re-created don't leak list.
personally speaking, bitmaps downloaded network, rather use lrucache
store bitmap
, assign keys them , backing them disk cache. assign keys each of them , work these keys. there libraries disklrucache
, picasso or novoda-imageloader lot.
same applies resource bitmaps: work keys - no need cache them. resource images should small enough device size + density , big enough fit needs.
it's opinion ...
Comments
Post a Comment