0

I wrote this in onBindViewHolder of RecycleViewAdapter,

Bitmap.createBitmap( 240, 420, Bitmap.Config.RGB_565);

And I got OutofmemoryError when scrolling my RecycleView. Down size of image is not good solution because error will happen when memory not enough.

Please help, thanks.

2
  • why do you need to createBitmap in onBindViewHolder ? Commented Jul 23, 2015 at 6:49
  • I have come across this issue couple of time and resolved using following link developer.android.com/training/displaying-bitmaps/… Commented Jul 23, 2015 at 6:52

1 Answer 1

2

Ofcourse it gives you OutOfMemory Exception.

Do you know how many times does your adapter call the onBind method?

A LOT. And you create a bitmap every time. You don't reuse it, you don't recycle it, you create it over and over again.

What do you use that Bitmap for more exactly? Maybe you don't even need to create it every time.

You should use a cache mechanism, you can use a library to display the Bitmap (like Universal Image Loader, Glide, Picasso, Volley, Lazy loading).

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks DDsix, but I need difference size, color bitmap in each item of list. I try with create one bitmap, resize and change color when call onBindViewHolder but performance of list is very bad.
So you only need to display a colored square of different sizes on every row? There are other ways of doing this. Bitmaps are not very efficient, you know
I need a bitmap to make input for asynctask, it must be a bitmap here. Trust is I must call this 'mImageFetcher.setLoadingImage(Bitmap)' once in constructor of adapter, but each image view in adapter, I have difference loading type (bitmap).
I just wanted to help you and get you to think outside the box. If you "MUST" use a bitmap, then I invite you to it. Good luck getting rid of that OutOfMemory excpetion, though.
In software, there is always another way :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.