Diff b/w bitmap.recycle() and bitmap=null

前端 未结 3 703
难免孤独
难免孤独 2020-12-11 16:48

I am in a situation where I have used a for loop to download a set of images and I am converting it into bitmap images. So in order to avoid OutOfMemory error, I am trying t

3条回答
  •  清歌不尽
    2020-12-11 17:06

    Calling recycle() indicates to the system that you are finished using that resource and that the system may now free the unmanaged memory that it was using. Once you have disposed of a resource in this way, its behaviour is usually undefined (one would reasonably expect it to simply no longer work).

    Setting the reference to null afterwards has two benefits:

    • You won't have stale references to objects that won't work when you try to use them
    • The garbage collector will know to clean up the managed side of the bitmap object, freeing even more memory

提交回复
热议问题