Reputation: 466
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.
Upvotes: 0
Views: 370
Reputation: 1985
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).
Upvotes: 2