android - WebView - memory leaks in a simple code on devices <= 4.1 -


my test code:

public class myactivity extends appcompatactivity {     webview mywebview;     relativelayout webviewlayout;      /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.mylayout);         webviewlayout = (relativelayout) findviewbyid(r.id.webviews);         mywebview = new webview(this);         webviewlayout.addview(mywebview);     } } 

causes memory leak in webview on 4.1 device (i use mat analysis):

class name java.lang.thread @ 0x4212f6b8 webviewcorethread thread '- <java local>, target android.webkit.webviewcore$webcorethread @ 0x4205d390 '- core android.webkit.webviewcore @ 0x4212f608 '- mcontext com.packagename.myactivity 

i have added ondestroy():

@override public void ondestroy() {     webviewlayout.removeallviews();     if(mywebview != null) {         mywebview.removeallviews();         mywebview.onpause();         mywebview.getsettings().setjavascriptenabled(false);         mywebview.destroy();         mywebview = null;     }     super.ondestroy(); } 

but on 4.1 memory leak remains. tried use getapplicationcontext() instead [this], result same.

on 4.4 device no memory leaks. bug in webview on <=4.1 ? possible fix it?

thanks!


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -