Android Bitmap causing memory leak? -


i have tried solutions find , none of them help. of them talk recycling bitmap isn't option me. app doing image processing in separate thread ui , use paint draw solid circle @ location image processing algorithm returns. here code -

    private runnable runnetwork = new runnable()    {     public void run()      {         if(!destroyflag)         {             bprocessing = true;                       start = systemclock.elapsedrealtime();             locations = calltorch(torchstate, previewsizewidth, previewsizeheight, framedata,networkloop);              stop = systemclock.elapsedrealtime();             wholeloop = (float) ((stop-start)*0.001);             fps = 1/wholeloop;             start = systemclock.elapsedrealtime();              if(locations[0] != 0)             {                 bitmap.erasecolor(0);                 for(int = 0; < locations.length; i+=4)                 {                     if(locations[i+2] != 0)                     {                         mcanvas.drawcircle(locations[i], locations[i+1], 10, p);                         mcanvas.drawtext("face", locations[i], locations[i+1]+15, p);                      }                 }             }             else                 bitmap.erasecolor(0);              mycameraclass.setimagebitmap(bitmap);             stop = systemclock.elapsedrealtime();             displayloop = (float) ((stop-start) * 0.001);              networkpercentage = (networkloop/wholeloop)*100;              cameraactivity.detailstext.settext("****profiling information****\n" + "time network = " + networkloop + " s\ntime whole loop = " +                         wholeloop + " s\nnetwork takes " + networkpercentage + "% of computation time" + "\ntime display = " + displayloop + "s \nframe rate =" + fps);              bprocessing = false;         }     }   }; 

i reuse same bitmap draw on cannot recycle it. there reason should cause memory leak? pretty bad 1 too. app can barely run half minute before crashes.

edit: more code fragments relavent bitmap creation

 public class cameraclass implements surfaceholder.callback, camera.previewcallback  {     private camera mcamera = null; private imageview mycameraclass = null;     public bitmap bitmap = null; private int[] pixels = null; private byte[] framedata = null; private int imageformat; private int previewsizewidth; private int previewsizeheight; private boolean bprocessing = false; float start, stop, networkloop, wholeloop, fps, displayloop, networkpercentage = 0; handler mhandler = new handler(looper.getmainlooper()); public long torchstate = 0; private boolean destroyflag = false; paint p = new paint(); canvas mcanvas; int[] locations;  public cameraclass(int previewlayoutwidth, int previewlayoutheight, imageview cameraclass) {     previewsizewidth = previewlayoutwidth;     previewsizeheight = previewlayoutheight;     mycameraclass = cameraclass;     bitmap = bitmap.createbitmap(1280, 768, bitmap.config.argb_8888);     mcanvas = new canvas(bitmap);     p.setantialias(true);     p.setcolor(color.red);     p.setstrokewidth((float)15.0);     p.settextsize(100); } 

above class creates bitmap. class called activity shown below -

public class cameraactivity extends activity {  private framelayout mainlayout; private imageview mycameraclass = null; private cameraclass campreview; private int previewsizewidth, previewsizeheight; static assetmanager assetmanager; static textview detailstext; button back;  public void oncreate(bundle savedinstancestate)  {     super.oncreate(savedinstancestate);      getwindow().setflags(windowmanager.layoutparams.flag_fullscreen,                 windowmanager.layoutparams.flag_fullscreen);      requestwindowfeature(window.feature_no_title);        assetmanager = getassets();      setcontentview(r.layout.activity_camera);      = (button) findviewbyid(r.id.back);     back.setonclicklistener(buttonhandler);      detailstext = (textview) this.findviewbyid(r.id.details);      mycameraclass = new imageview(this);      surfaceview camview = new surfaceview(this);     surfaceholder camholder = camview.getholder();      previewsizewidth = mainactivity.width;     previewsizeheight = mainactivity.height;      campreview = new cameraclass(previewsizewidth, previewsizeheight, mycameraclass);     camholder.addcallback(campreview);      camholder.settype(surfaceholder.surface_type_push_buffers);      mainlayout = (framelayout) findviewbyid(r.id.framelayout);     mainlayout.addview(camview, new layoutparams(1280, 768));     mainlayout.addview(mycameraclass, new layoutparams(1280, 768));  } 


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -