【发布时间】:2012-09-22 15:33:02
【问题描述】:
我从资产中获取图像并分配给 imageView,一切正常,但是当我看到堆内存大小时,当我一次又一次加载同一页面时,它会继续增长,下面是我用来从中获取图像的代码资产文件夹。
private Bitmap getBitmapFromAsset(String strName) throws IOException
{
AssetManager assetManager = getAssets();
InputStream istr = assetManager.open(strName);
Bitmap bitmap = BitmapFactory.decodeStream(istr);
return bitmap;
}
//Code to assign bitmap to imageview
ImageView itemImage = (ImageView) findViewById(R.id.itemImage);
try {
Bitmap bm = getBitmapFromAsset("full/" + Uri.parse(menuItem.getFullImage()).getLastPathSegment());
itemImage.setImageBitmap(bm);
} catch (IOException e) {
e.printStackTrace();
}
这就是我正在做的所有事情,有没有我需要回收位图的地方?
【问题讨论】:
-
见这里thiagorosa.com.br/en/how-to/minimize-outofmemory-errors。我经常使用它,但没有调用 GC。在我看来,它没有任何用处,而且经常被用来掩饰罪恶;)
标签: java android memory-leaks