I want to show a ViewPager
with ~50 pages, each containing a different image. Using Picasso, the first 20-25 pages work perfectly. However, at that point I get an OutOfMemoryError
, and no images are loading at all:
Throwing OutOfMemoryError "Failed to allocate a 7477932 byte allocation with 1932496 free bytes"
I'm using the following code in my PagerAdapter
:
@Override
public Object instantiateItem(final ViewGroup container, final int position) {
View view = getView();
Picasso picasso = getImageLoader(mContext);
picasso.load(getUrl(position)).fit().into((ImageView) view.findViewById(R.id.imageview));
container.addView(view);
return view;
}
@Override
public void destroyItem(final ViewGroup container, final int position, final Object object) {
container.removeView((View) object);
}
What can I do to avoid this?