似乎BitmapRegionDecoder有内存泄漏.如果我运行下面的代码,我可以看到设备上的本机内存使用量增加.最终应用程序将因崩溃而死亡,因为由于缺少可用内存,Android操作系统将终止它:
public void doClick(View v) {
String bitmapFileName = "/mnt/sdcard/Wallpaper Images/-398300536.jpg";
BitmapRegionDecoder dec;
try {
for (int i = 0; i < 100; i++) {
FileInputStream is = new FileInputStream(bitmapFileName);
dec = BitmapRegionDecoder.newInstance(is, false);
// I am not even doing anything with bitmap region decoder!
is.close();
dec.recycle();
System.gc();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
运行adb shell dumpsys meminfo将报告以下事先执行上面的代码(参见3273 kB本机分配):
Applications Memory Usage (kB):
Uptime: 63276459 Realtime: 469577132
** …Run Code Online (Sandbox Code Playgroud)