android - Out of memory Error in picasso -


i using picasso library loading multiple images on grid server. have 3 fragments on main activity.each fragment loads multiple images on grid server using picasso. when navigate fragment fragment continously ,the fragments loads slow , after half hour app crash due out of memory error in picasso. how resolve it?

public class myalbimageadapter extends baseadapter {      public list<myalbum> _albumlist=appcontroller.getinstance().getprefmanger().getmyalbums();     public static int flag=0;     private layoutinflater inflater;      private displayimageoptions options;     imageloaderconfiguration config;     imageloader imageloader;     context c;     public myalbimageadapter(context context,list<myalbum> album)      {          _albumlist=album;          inflater = layoutinflater.from(context);          this.c=context;      }      @override     public int getcount() {         return _albumlist.size();     }      @override     public object getitem(int position) {         return null;     }      @override     public long getitemid(int position) {         return position;     }       // create new imageview each item referenced adapter     public view getview(int position, view convertview, viewgroup parent) {          view v = convertview;               final viewholder holder;         if(v == null)         {            v = inflater.inflate(r.layout.myalb_outer_griditem, parent, false);            holder = new viewholder();            holder.imageview = (imageview) v.findviewbyid(r.id.thumbnail);            holder.t1 = (textview) v.findviewbyid(r.id.alb_name);            holder.t2 = (textview) v.findviewbyid(r.id.usr_name);            v.settag(holder);         }         else          {             holder = (viewholder) v.gettag();         }         myalbum p = _albumlist.get(position);                    holder.t1.settext(p.getname());           picasso.with(c).load(appconst.base_image_url+p.getcover()).fit().centercrop().into(holder.imageview);          return v;}} 

please help, tried many links on net didn't find useful.

error is:

07-10 12:40:46.230: e/dalvikvm(17680): out of memory: heap size=131107kb, allocated=129839kb, limit=65536kb 07-10 12:40:46.240: e/dalvikvm(17680): info: footprint=131043kb, allowed footprint=131107kb, trimmed=1452kb 07-10 12:40:46.240: e/bitmap_jni(17680): create bitmap failed. 07-10 12:40:46.240: e/bitmap_jni(17680): failed create skbitmap! 07-10 12:40:48.012: e/dalvikvm-heap(17680): out of memory on 198896-byte allocation.

similar ques. android picasso imageview - out of memory exception memoryleak

when android "unwraps" image (i.e. decodes bitmap), use 4 bytes per pixel. count number of pixels, multiply 4 , 20 (number of images) , you'll close 100mb figure. instance, if images have 1,000,000 pixel resolution, 1,000,000 x 4 x 20 = 80mb.

use kind of lru cache or similar (or alternatively use universal image loader library handles caching you) , load bitmaps when need them.


Comments