2
我使用下面的代码来减少位图大小并保存它的内存。但是当我使用它时,消耗的RAM内存不是释放。什么是解决方案?我在usting下面的方法后调用System.gc(),但不会影响。回收后未释放位图消耗RAM内存
public static void compress_save(Bitmap input, String path, int dim) throws IOException {
FileOutputStream out = new FileOutputStream(path);
input = Bitmap.createScaledBitmap(input, Generals.img_width, Generals.img_height, true);
input.compress(Bitmap.CompressFormat.JPEG, dim, out);
out.flush();
out.close();
input.recycle();
}
我致电上述功能的活动成果
Uri selectedImageUri = data.getData();
imgPath = Util.getRealPathFromURI(MainActivity.this, selectedImageUri);
Bitmap bitmap = BitmapFactory.decodeFile(imgPath);
try {
imgPath = Generals.App_Directory + "/temp/" + SystemClock.currentThreadTimeMillis();
ImageUtil.compress_save(bitmap, imgPath, 50);
bitmap.recycle();
System.gc();
confirmDialog();
} catch (IOException e) {
FileLogException.print(e);
}
你没有回收更大的位图('Bitmap input'参数) – pskink
你有没有试过用'MAT'来检查谁仍然持有参考? – thepoosh
再次使用MAT并查看谁拥有对位图的引用,调用System.gc实际上并不会导致gc – thepoosh