-1

I am creating a app with 160 plus images all are between 150 and 300KB. And after testing the app in crashes giving me a out of memory error. I have read posts on here about that but when i implement bitmap.recycle() it gives a me a red line underneath the bitmap.

heres my code:

next.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM1);
            imageView.setImageResource(R.drawable.sample);
            bitmap.recycle();
            slider.animateClose();

        } 
    });

Can anyone plese help?

Allrounder
  • 685
  • 2
  • 9
  • 20
  • Possible duplicate: http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object . – Marcelo Nov 10 '12 at 19:50

1 Answers1

1

You have to have a BitMap to call bitmap.recycle(). BitMap.recycle() removes the bitmap you have write before the .recycle(). Example:

Bitmap someBit= new Bitmap (this);
someBit.recycle();

Based on the code above this is the right answear.

Magakahn
  • 498
  • 9
  • 31
  • Hi Magakahn. Thanks for that but i now seem to get an error inder new Bitmap (this); – Allrounder Nov 10 '12 at 20:20
  • I do not think you understand my answear. If you recycle your newly generated BitMap it will make no difference. someBit.recycle() does only work if this BitMap is the one takeing up the memory. – Magakahn Nov 10 '12 at 20:27
  • @Keithk are you going to accept my answear? bitmap.recycle() will not help you unless the bitmap is the the thing causeing outOfMemory Exeption. – Magakahn Nov 11 '12 at 09:59
  • Yeah sorry about that, This problem is causing me alot of grey hairs. I'll mark is as correct now. Although I have posted a detailed description of the problem I am having. heres the link: http://stackoverflow.com/questions/13330188/having-a-really-weird-outof-memory-error-in-my-app. – Allrounder Nov 11 '12 at 10:12