i've some leaks problems. What i'm doing is loading some pictures in a table. I've created an asyncronous class for loading images.
In my table while i'm cycling the array I add my class
final LoaderImageView image = new LoaderImageView(getContext(),vgood[i].getImageUrl(),(int)(ratio *80),(int)(ratio *80));
row.addView(image);
In my asyncronous class i'm loading images from this
return Drawable.createFromStream(((java.io.InputStream)new java.net.URL(url).getContent()), "name");
Called by
public void setImageDrawable(final String imageUrl) {
mDrawable = null;
mSpinner.setVisibility(View.VISIBLE);
mImage.setVisibility(View.GONE);
new Thread(){
public void run() {
try {
mDrawable = getDrawableFromUrl(imageUrl);
imageLoadedHandler.sendEmptyMessage(COMPLETE);
} catch (MalformedURLException e) {
imageLoadedHandler.sendEmptyMessage(FAILED);
e.printStackTrace();
} catch (IOException e) {
imageLoadedHandler.sendEmptyMessage(FAILED);
e.printStackTrace();
}
};
}.start();
}
When i've a lot of images to load the app crashes due to out of memory caused by this line
return Drawable.createFromStream(((java.io.InputStream)new java.net.URL(url).getContent()), "name");
How can i fix that? where i'm going wrong?
thank you
Never load any tiles that you don't need. "am collecting all bitmaps from sdcard" suggests that you are decompressing every image you might ever need, which would be the wrong approach.
Use smaller tiles. 256x256 is a good size.
Load them as Config.RGB565 (ie 16bpp).
Regularly recycle() Bitmaps you don't need.
Basically you need to implement some sort of most-recently-used (MRU) Bitmap cache
Extrated From
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.