0

Possible Duplicate:
Android: Strange out of memory issue while loading an image to a Bitmap object
java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android

First Activity

public class Main_AllLatestNews extends ListActivity

Second Activity (load 10 or more images)

@Override
protected void onDestroy() {
super.onDestroy();

unbindDrawables(findViewById(R.id.RootView));
System.gc();
}

private void unbindDrawables(View view) {
    if (view.getBackground() != null) {
    view.getBackground().setCallback(null);
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
        unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
    ((ViewGroup) view).removeAllViews();
    }
}

I am using this to call image

if (!imagepath[i].toString().equals("no picture")) {
            try {
                aURL = new URL("http://www.orientaldaily.com.my/" + imagepath[i]);
                URLConnection conn = aURL.openConnection();
                conn.connect();
                InputStream is = conn.getInputStream();
                BufferedInputStream bis = new BufferedInputStream(is);
                Bitmap bm = BitmapFactory.decodeStream(bis);
                bis.close();
                is.close();
                imageview = (ImageView) findViewById(R.id.image_categoryallnewstitle);
                imageview.setScaleType(ScaleType.CENTER_CROP);
                imageview.setImageBitmap(bm);

            } catch (IOException e) {
                Log.e("DEBUGTAG", "Remote Image Exception", e);
            }
        }

I implement this method before i call those images but yet still got memory leak and

bitmap size exceeds VM budget

Any problem in my code or got other solutions to solve this?

Community
  • 1
  • 1
Alan Lai
  • 1,088
  • 7
  • 18
  • 41
  • 1
    Stop it already with those questions! Such question is posted twice a day. The related section is already not enough to fit all the same questions! Do a search before posting here! http://developer.android.com/training/displaying-bitmaps/index.html – Boris Strandjev May 03 '12 at 07:27
  • nop, new user i tried to put ondestroy but still cannot because new exception here `java.lang.UnsupportedOperationException: removeAllViews() is not supported in AdapterView ` – Alan Lai May 03 '12 at 08:07

0 Answers0