android - LeakCanary how to interpret log -
i have been stuck 2 days memory leak problem app, have searched on internet solutions , encountered library called leakcanary. after adding necessary dependencies, launched app again. trying detect leak rotating phone , after couple of rotations app shows log. problem don't know how interpret log.
here log leakcanary shows:
02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: in com.carlos.capstone:1.0:1. 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * com.carlos.capstone.mainactivity has leaked: 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * gc root static android.support.v4.content.localbroadcastmanager.minstance 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references android.support.v4.content.localbroadcastmanager.mreceivers 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references java.util.hashmap.table 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references array java.util.hashmap$hashmapentry[].[1] 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references java.util.hashmap$hashmapentry.key 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references com.carlos.capstone.fragmentmain$1.this$0 (anonymous class extends android.content.broadcastreceiver) 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references com.carlos.capstone.fragmentmain.mviewpager 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references android.support.v4.view.viewpager.madapter 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references com.carlos.capstone.fragmentmain$adapter.mcurrentprimaryitem 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references com.carlos.capstone.fragmentamerica.madapterindexes 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references com.carlos.capstone.adapters.indexesadapter.mcursor 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references android.content.contentresolver$cursorwrapperinner.mcursor 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references android.database.sqlite.sqlitecursor.mdatasetobservable 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references android.database.datasetobservable.mobservers 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references java.util.arraylist.array 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references array java.lang.object[].[0] 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references android.widget.cursoradapter$mydatasetobserver.this$0 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * references com.carlos.capstone.adapters.indexesadapter.mcontext 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * leaks com.carlos.capstone.mainactivity instance 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * reference key: 4483f896-bc1c-40a1-9bd6-a96ab0d792a0 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * device: genymotion generic google nexus 5 - 5.1.0 - api 22 - 1080x1920 vbox86p 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * android version: 5.1 api: 22 leakcanary: 1.3.1 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * durations: watch=6790ms, gc=116ms, heap dump=1357ms, analysis=4544ms 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * details: 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: * class android.support.v4.content.localbroadcastmanager 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: | static $staticoverhead = byte[] [id=0x12d08781;length=40;size=56] 02-05 13:45:14.721 4258-4716/com.carlos.capstone d/leakcanary: | static ...
updated fragmentamerica fragment
package com.carlos.capstone; import android.app.activity; import android.content.intent; import android.database.cursor; import android.net.uri; import android.os.bundle; import android.support.annotation.nullable; import android.support.customtabs.customtabsintent; import android.support.v4.app.fragment; import android.support.v4.app.loadermanager; import android.support.v4.content.contextcompat; import android.support.v4.content.cursorloader; import android.support.v4.content.loader; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.view.viewtreeobserver; import android.widget.scrollview; import android.widget.textview; import android.widget.toast; import com.carlos.capstone.adapters.indexesadapter; import com.carlos.capstone.adapters.rssnewsadapter; import com.carlos.capstone.customtabs.customtabactivityhelper; import com.carlos.capstone.database.capstonecontract; import com.linearlistview.linearlistview; /** * created carlos on 19/01/2016. */ public class fragmentamerica extends fragment implements loadermanager.loadercallbacks<cursor> { private linearlistview mverticallistview; private linearlistview mindexeslistview; private scrollview mscrollview; private boolean mrotationdone=false; private static final string key_posx="x_pos"; private static final string key_posy="y_pos"; private static final int news_loader=0; private static final int indexes_loader=1; private rssnewsadapter madapter; private indexesadapter madapterindexes; private static final string selectionnews =capstonecontract.newsentity.region + " =?"; private static final string[] selectionargsnews =new string[]{"america"}; private static final string selectionindexes=capstonecontract.indexesentity.region + " =?"; private static final string[] selectionargsindexes=new string[]{"america"}; private static final string sortbydatedesc = capstonecontract.newsentity.date + " desc"; private int x; private int y; linearlistview.onitemclicklistener mlistener = new linearlistview.onitemclicklistener() { @override public void onitemclick(linearlistview parent, view view, int position,long id) { final textview tvlink,tvtitle; tvlink= (textview) view.findviewbyid(r.id.txturllink); tvtitle= (textview) view.findviewbyid(r.id.txttitulo); uri uri=null; uri = uri.parse(tvlink.gettext().tostring()); //customization possibilities customtabsintent customtabsintent = new customtabsintent.builder() .settoolbarcolor(contextcompat.getcolor(getactivity(),r.color.colorprimary)) .setshowtitle(true) .build(); customtabactivityhelper.opencustomtab(getactivity(), customtabsintent,uri, //in case user doen't have chromium v 45 installed, offer alternative //browser experience webview new customtabactivityhelper.customtabfallback() { @override public void openuri(activity activity, uri uri) { intent intent=new intent(getactivity(),detailsnewsactivity.class); intent.putextra("url",tvlink.gettext()); intent.putextra("title",tvtitle.gettext()); startactivity(intent); } }); } }; @nullable @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) { view view=inflater.inflate(r.layout.fragment_america,container,false); mverticallistview = (linearlistview) view.findviewbyid(r.id.verticallist); mindexeslistview= (linearlistview) view.findviewbyid(r.id.indexeslistamerica); mscrollview= (scrollview) view.findviewbyid(r.id.scrollviewam); mscrollview.getviewtreeobserver().addonscrollchangedlistener(new viewtreeobserver.onscrollchangedlistener() { @override public void onscrollchanged() { x=mscrollview.getscrollx(); log.d("villanueva","x pos:"+mscrollview.getscrollx()+",y pos:"+mscrollview.getscrolly()); y=mscrollview.getscrolly(); } }); madapter =new rssnewsadapter(getactivity().getapplicationcontext(),null,news_loader); madapterindexes=new indexesadapter(getactivity().getapplicationcontext(),null,indexes_loader); //set both adapters mindexeslistview.setadapter(madapterindexes); mverticallistview.setadapter(madapter); mverticallistview.setonitemclicklistener(mlistener); getloadermanager().initloader(news_loader,null,this); getloadermanager().initloader(indexes_loader,null,this); if(savedinstancestate==null) { } else { mrotationdone=true; //scroll saved position mscrollview.scrollto(savedinstancestate.getint(key_posx),savedinstancestate.getint(key_posy)); } toast.maketext(getactivity(),"oncreateviewamerica",toast.length_short).show(); return view; } @override public void onresume() { super.onresume(); toast.maketext(getactivity(),"onresumeamerica",toast.length_short).show(); } @override public void onsaveinstancestate(bundle outstate) { super.onsaveinstancestate(outstate); outstate.putint(key_posx,mscrollview.getscrollx()); outstate.putint(key_posy,mscrollview.getscrolly()); } @override public loader<cursor> oncreateloader(int id, bundle args) { if (id==news_loader) { return new cursorloader(getactivity().getapplicationcontext(), capstonecontract.newsentity.content_uri, null, selectionnews, selectionargsnews, sortbydatedesc); } else if(id==indexes_loader) { return new cursorloader(getactivity().getapplicationcontext(), capstonecontract.indexesentity.content_uri,null,selectionindexes,selectionargsindexes,null); } return null; } @override public void onloadfinished(loader<cursor> loader, cursor data) { switch(loader.getid()) { case news_loader: madapter.swapcursor(data); break; case indexes_loader: madapterindexes.swapcursor(data); break; } mscrollview.postdelayed(new runnable() { @override public void run() { mscrollview.scrollto(x,y); } },200); log.d("villanueva","move x pos:"+x+",y pos:"+y); } @override public void onloaderreset(loader<cursor> loader) { switch(loader.getid()) { case news_loader: madapter.swapcursor(null); break; case indexes_loader: madapterindexes.swapcursor(null); break; } } @override public void ondestroy() { super.ondestroy(); // exampleapplication application = (exampleapplication) getactivity().getapplicationcontext(); // application.mustdie(this); } }
i'm sure problem indexadapter, if comment out following lines of code problem dissapears;
getloadermanager().initloader(indexes_loader,null,this);
and
return new cursorloader(getactivity().getapplicationcontext(), capstonecontract.indexesentity.content_uri,null,selectionindexes,selectionargsindexes,null);
when create indexesadapter
, instead of passing this
in constructor, use this.getapplicationcontext()
.
Comments
Post a Comment