Can anybody point me at resources with best practice on clearing sensitive runtime images?
Consider a scenario where a sensitive image is downloaded from a server at runtime, loaded into a Bitmap object, and is then displayed in an ImageView in a Fragment.
When the user leaves that screen, or the app is exited/put in the background for a long time, then I want to clear that image data so that it isn’t easy to recover.
I was wondering if there is a reliable way to zero out the bitmap data as soon as the Fragment containing the image is destroyed?
This feel tricky to me, as Bitmaps are usually returned as immutable objects, e.g. BitmapFactory.decodeByteArray
Decode an immutable bitmap from the specified byte array.
Presumably I would have to create a mutable Bitmap
and then copy over its data?
It looks like recycle()
won’t help me, as that will just mark the data as available for garbage collection, it won’t wipe it.
You can simply clear the
It will fill the bitmap with
color and erase everything on it. However, if you have no any references to your bitmap (e.g. you’ve set
that was containing your
the garbage collector should collect it shortly.