I have a RecyclerView which is showing a CardView. In the CardView there are two items:
The bitmap is created dynamical.
After some up and down scrolling I get an OutOfMemoryException.
I'm not sure how to handle it? Should I use LRUCache? Or third party libraries like Picasso - which seems to only work on urls and ids?
Any help appreciated
Update:
public class ManageProfileAdapter : RecyclerView.Adapter
{
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
ManageProfileViewHolder vh = holder as ManageProfileViewHolder;
vh.Caption.Text = profiles[position].Name;
vh.Thumbnail.SetProfile(profiles[position].Profile);
}
}
The thumbnail class is a custom class derived from View (which includes bitmap):
public class ThumbnailView : View
{
private Canvas DrawCanvas;
private Bitmap CanvasBitmap;
}
The bitmap is drawn on the Canvas.
This guided me in the right direction:
You must be creating bitmap data somewhere in your code again and again. Check it out
The bitmap in my thumnail view is not removed by the garbage collector.
The solution is:
I got no memory exceptions anymore and in logcat my highest usage is 30mb ram.
Lesson Learned: You have to dispose bitmaps yourself in RecyclerView
Thank you very much.