Android也OOM——OutofMemory

2013-07-06

导语:最近在开发新软件,对图片做一些处理,出现了个OOM,搞了大半天。哭


正文:对于从图库或者照相机里面获取的图片,通常情况下都比较大,如果没有好好处理,及时释放recycle,经常会遇到内存问题。但是我程序中用完之后及时释放了,只是在两个进程中跳转,有可能存在缓存,悲催啊。

最后,在使用URI获取图片的时候采用RGB_565格式,结果就OK了。

(对Android & Java的了解,果然还只是皮毛,有待深入)

//前
ContentResolver cr = getContentResolver();
mBitmap = compressBmp(BitmapFactory.decodeStream(cr.openInputStream(uri)));

//后
ContentResolver cr = getContentResolver();
Options opts = new Options();
//opts.inPurgeable = true; 
//opts.inInputShareable = true;
opts.inPreferredConfig = Config.RGB_565; 
mBitmap = compressBmp(BitmapFactory.decodeStream(cr.openInputStream(Uri.parse(uri)), null, opts));


以上!

 

结尾: 1)坚持写写博客

      2)继续学习开发

      3)我是IT程序猿


你可能感兴趣的:(Android也OOM——OutofMemory)