我有一个懒加载图片的
我的
我无法理解的是,我已经在try catch语句中写了代码:
ListView
。我还使用这个教程来更好地管理内存,并在我的ArrayList
中存储了SoftReference
位图图像。我的
ListView
从数据库中加载8张图片,一旦用户滚动到底部,它就会加载另外8张图片。当图片数量超过35张时,我的应用程序会因为OutOfMemoryError
而强制关闭。我无法理解的是,我已经在try catch语句中写了代码:
try
{
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(image, 0, image.length, o);
//Find the correct scale value. It should be the power of 2.
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while(true)
{
if(width_tmp/2 < imageWidth || height_tmp/2 < imageHeight)
{
break;
}
width_tmp/=2;
height_tmp/=2;
scale++;
}
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
bitmapImage = BitmapFactory.decodeByteArray(image, 0, image.length, o2);
}
catch (Exception e)
{
e.printStackTrace();
}
但是try catch块没有捕获OutOfMemory异常,据我所知,当应用程序内存不足时,SoftReference位图图像应该被清除,以防止抛出OutOfMemory异常。
我在这里做错了什么?