Where to properly deallocate bitmap on Android View?

Viewed 2591

I have a custom View, that draws a bunch of stuff including bitmaps. I want to cache this drawing onto a bitmap, so that I just need to draw one single bitmap inside onDraw, rather than repeating these drawing tasks and calculation.

Bitmaps need to be recycled after we are no longer using it. I don't see onDestroy() or anything remotely similar in the View class. Is there a callback method I can override to achieve this?

public void <insert_callback_here>() {
    cachedBitmap.recycle();
}

There is no animation. This is a static image. There are plenty of calculations done to draw the image, so I'd rather do it once on onMeasure().

1 Answers
Related