0

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

I know that there are many topics about this allready, but whatever I try it doesn't seem to work.

I've tried several onDestroy tricks including recycling the bitmap, putting it to null, etc etc. Not sure if my code is any different than other situations? It kind of seems that way... I'm using the TouchImageView extend so I can use pinch zoom so maybe that makes it more complex?

Anyway here's my code. Could anyone please point out how I can fix this (btw without downscaling the bitmap) please?

    public class PageActivity extends Activity {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.page);

            Intent parent = getIntent();
            int pagenumber = parent.getIntExtra("pagenumber", 1);
            int resID = getResources().getIdentifier("page"+pagenumber , "drawable", getPackageName());

            TouchImageView img = new TouchImageView(this);
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resID);
            img.setImageBitmap(bitmap);
            img.setMaxZoom(4f);

            LinearLayout rootview = (LinearLayout) findViewById(R.id.RootView);
            rootview.addView(img);
        }
    }
Community
  • 1
  • 1
Big Dutchee
  • 93
  • 3
  • 9
  • I notice onDestroy() isnt begin called because I'm using a tabhost. So I've tried putting a ontablistener in it and call ondestroy manually that way, but then it gets called when the activity isnt even started yet so I tries to use a recycled bitmap when I put the recycle() stuff in it :S – Big Dutchee Oct 03 '12 at 08:58
  • I've made up a great way to stop the memory leak, so can this topic be reopened so I can post it? I think others might benefit from it. – Big Dutchee Oct 03 '12 at 19:42

1 Answers1

0

As you are saying, you have used everything from cropping to recycling, now try with WeakReferences as well.

If this also does not help, then you may have memory leak in your code.

Please see my answer on same issue: bitmap size exceeds Vm budget error android

Its a generic answer, try with all methods that I have mentioned. One of them should work for you :)

Thank you.

Community
  • 1
  • 1
Shrikant Ballal
  • 7,067
  • 7
  • 41
  • 61