Android - Bitmap and memory management?

后端 未结 4 858
终归单人心
终归单人心 2020-12-17 16:56

I\'ve seen in a lot of samples, that developers call recycle() on bitmap, and then set it to null. Why is this necessary, doesn\'t the garbage coll

4条回答
  •  爱一瞬间的悲伤
    2020-12-17 17:26

    Join the club. It kind of does but not quite.

    The thing is that in the pre-Honeycomb versions of Android the memory for bitmaps was (is) allocated from unmanaged memory, which creates all sorts of problems. It is still released but from the finalizer of the bitmap object implementation. Which means that it will take at least 2 passes of GC to collect it. Also if for whatever reason the finalizer fails to execute - you got the picture. Another thing is - it is really difficult to trace - DDMS does not see it and neither does MAT

    For Android 3.0 this has been changed and bitmaps are implemented over managed byte arrays, but for the older phones...

提交回复
热议问题