2013年5月6日に横浜Android and モバイルOS プラットフォーム部で発表した資料です。Androidアプリ開発者向けにOutofMemoryErrorの発生原理とメモリ管理について最新事情を加味してまとめました。Androidアプリにおけるメモリ事情は(初期に比べたら)改善していますが、OpenCVなど画像処理の需要、高解像度対応を踏まえると依然として十分とは言いがたいユースケースもあります。そんな中でメモリ資源をうまく使うための指標となれば幸いです。
20. public class BitmapFactory extends Object
android.graphics.BitmapFactory
Class Overview
◦ Creates Bitmap objects from various sources, including files,
streams, and byte-arrays.
Public Methods
◦ static Bitmap decodeFile(String pathName,
BitmapFactory.Options opts) Decode a file path into a
bitmap.
◦ static Bitmap decodeResource(Resources res, int id)
Synonym for decodeResource(Resources, int,
android.graphics.BitmapFactory.Options) will null Options.
20
21. Free up the memory associated with this bitmap's
pixels, and mark the bitmap as "dead", meaning
it will throw an exception if getPixels() or
setPixels() is called, and will draw nothing.
isRecycled() Returns true if this bitmap has been
recycled.
「今は使わない」というタイミングで呼んでおくと
メモリが不足したときに自動的に解放してくれる
21