Android Bitmap Memory Leak, what to do more

淺唱寂寞╮ 提交于 2019-12-24 10:27:36

问题


I'm building an app where you have the function to upload a post with an image. When the user picks the image I show a thumbnail of it but when I change the screen orientation I get a memory leak. I managed to get it down to the point where it takes about 25 orientation changes to leak memory but can I completely avoid it?

This is the code I use for the bitmap,

private ImageView miniPicture;
private String imagePath;
private WeakReference<Bitmap> imageBitmap;

....

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
imageBitmap = new WeakReference<Bitmap>(BitmapFactory.decodeFile(imagePath, options));                
miniPicture.setImageBitmap(imageBitmap.get());

来源:https://stackoverflow.com/questions/5734892/android-bitmap-memory-leak-what-to-do-more

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!