There is no guaranteed way to force a garbage collection, only a way to suggest one using System.gc()
. Since the bitmaps pixel data lives in native memory outside of the dalvik heap, providing a native function (in this case recycle()
) will give us the opportunity to clean up this pixel data for sure (eventually). Please note that when using recycle()
there is not much more you can do with that bitmap.
The issue you are having is that you are calling recycle()
on a bitmap, which you are still trying to use.
To answer your question, yes, setting bitmap to null after you have recycled it is a good idea, but it may also be redundant. Always try to recycle your bitmaps when you are done with them.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…