Drawable vs Single reusable Bitmap better with memory?

后端 未结 2 409
情深已故
情深已故 2020-12-08 07:59

As I understand it (not that I\'m correct) Drawables are generally correctly removed from memory when the application is finished with them. Bitmaps however need to be manua

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 08:32

    Bitmaps do not need to be manually recycled. They are garbage collected just like Drawables and other objects. Similarly you don't need to unbind drawables, except in very specific situations. It seems that you read a lot of misleading information.

    Recycling bitmaps and unbinding drawable can be useful in some situations (for instance if your app manipulate large amounts of bitmap data or if you store drawable in a static manner.)

    The two examples you show at the beginning of your question are equivalent. If you load a drawable directly, bitmaps will be loaded on your behalf. If you load bitmaps manually and set them on an ImageView, they will be enclosed in drawables on your behalf.

    Use the first solution since it's simpler and don't worry about unbinding and other memory management techniques until you actually need them.

提交回复
热议问题