Reputation: 63
I was trying the hp.android answer in the https://stackoverflow.com/a/6779067/1236259 thread but my activity never invokes the onDestroy method
I have a ListView with images and I call to other activity by:
ImageButton imageButtonSeeMap = (ImageButton)this.findViewById(R.id.imageButtonSeeMap);
imageButtonSeeMap.setOnClickListener(new OnClickListener() {....
From the new activity I invoke the ListView activity again and in this point I´m getting the exeption: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
The image in the listview is created using:
thumb_u = new URL(lp.get(i).getImage());
thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");
imageViewPoi.setImageDrawable(thumb_d);
How can I release the memory of the images? The unbindDrawables in the onDestroy method is never invoked.
Any idea?
Upvotes: 0
Views: 992
Reputation: 17140
Images are beast in android, so OutofMemory exceptions are kinda something you might have to get used to. This should allow your listview to get images from the web and not crash yer app.
Assuming that the 2nd code block is from your ListView's adapter getView() method, try :
try {
thumb_u = new URL(lp.get(i).getImage());
thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");
imageViewPoi.setImageDrawable(thumb_d);
} catch (OutOfMemoryError e) {
System.gc();
thumb_u = new URL(lp.get(i).getImage());
thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");
imageViewPoi.setImageDrawable(thumb_d);
}
Upvotes: 1