/**
* Free the native object associated with this bitmap, and clear the
* reference to the pixel data. This will not free the pixel data synchronously;
* it simply allows it to be garbage collected if there are no other references.
* The bitmap is marked as "dead", meaning it will throw an exception if
* getPixels() or setPixels() is called, and will draw nothing. This operation
* cannot be reversed, so it should only be called if you are sure there are no
* further uses for the bitmap. This is an advanced call, and normally need
* not be called, since the normal GC process will free up this memory when
* there are no more references to this bitmap.
*/
public void recycle() {
if (!mRecycled && mNativePtr != 0) {
if (nativeRecycle(mNativePtr)) {
// return value indicates whether native pixel object was actually recycled.
// false indicates that it is still in use at the native level and these
// objects should not be collected now. They will be collected later when the
// Bitmap itself is collected.
//返回值指示原生像素对象是否实际被回收。 false 表示它仍在本机级别使用,
//现在不应收集这些对象。稍后将在收集 Bitmap 本身时收集它们。
mNinePatchChunk = null;
}
mRecycled = true;
}
}
翻译:
释放与此位图关联的本机对象,并清除对像素数据的引用。 这不会同步释放像素数据
; 如果没有其他引用,它只是允许它被垃圾收集。 位图被标记为“死”,这意味着如果调用 getPixels() 或 setPixels() 它将抛出异常,并且不会绘制任何内容。 此操作无法撤消,因此只有在您确定位图没有其他用途时才应调用它。 这是一个高级调用,通常不需要调用
,因为当没有更多对此位图的引用时,正常的 GC 过程将释放此内存。