【发布时间】:2013-07-31 14:34:40
【问题描述】:
我有严重的内存问题,我期待回收位图。
但是,我的应用正在使用 atm 构建一个包含多个位图的画廊(是的,已弃用),然后是多个画廊。
所以在一天结束时,应用看起来像(LinearLayout 样式):
*一些网页浏览量 *包含 7 张图片的画廊。 *一些网页浏览量 *一个有 10 张图片的画廊
等等。
所以我的想法是......一旦我显示了这些图像,并且它们在屏幕上,这些位图可以回收吗?
有没有办法回收整个图库组件?
非常感谢。
编辑:
我尝试了很多东西。我仍然收到错误java.lang.IllegalArgumentException: bitmap size exceeds 32bits
这是我的实际代码:
BitmapFactory.Options bfOptions=new BitmapFactory.Options();
bfOptions.inDither=false; //Disable Dithering mode
bfOptions.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared
bfOptions.inInputShareable=true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
bfOptions.inTempStorage=new byte[32 * 1024];
bfOptions.inInputShareable=true;
bfOptions.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = BitmapFactory.decodeFile(mUrls.get(position).getPath(), bfOptions);
inflatedImageView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 120, 120, false));
如您所见,我为位图设置了许多选项,并调整了它的大小并降低了它的质量。仍然发生同样的问题。
【问题讨论】:
-
为什么不用
ViewPager来实现图库呢?这是 Google 找到的链接:manishkpr.webheavens.com/… -
上次我使用这个时,一旦位图不再可见,您必须一次回收一个位图。
-
@gunar 因为编辑整个应用程序需要很长时间。我需要一种释放内存的方法。
-
还不错...所以:首先,您确定要加载最适合尺寸的图像吗?我的意思是你在做一些样本大小的解码吗?就像这篇文章中描述的那样:developer.android.com/training/displaying-bitmaps/index.html 然后,只有当imageview不再附加到视图时,才可以安全地回收位图。
-
是的,位图总是被调整为 150x150。当我执行 System.gc 时,它是否也会自动“清理”位图?
标签: android