When adding JavaScript support setJavaScriptEnabled (true) , when I click on the links, the application starts to take up a lot of memory, when I don’t add support, everything works fine, I don’t know why, help me figure it out.

public void onCreate(Bundle savedInstanceState) { mWebView = new WebView(getApplicationContext()); mWebContainer = (FrameLayout) findViewById(R.id.web_container); mWebContainer.addView(mWebView); mWebView.getSettings().setUserAgentString(""); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setPluginsEnabled(true); mWebView.getSettings().setPluginState(PluginState.ON); mWebView.getSettings().setDatabaseEnabled(true); mWebView.getSettings().setGeolocationEnabled(true); mWebView.getSettings().setSupportZoom(true); mWebView.getSettings().setSavePassword(true); mWebView.getSettings().setSaveFormData(true); } private static class HelloWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } protected void onDestroy() { super.onDestroy(); mWebContainer.removeAllViews(); mWebView.destroy(); mWebView = null; System.gc(); } } 

Created a simple webview - the same memory leak.

  • Well, in general, it can be more or less explained by the fact that interpreters (in particular, the embedded JavaScript interpreter) need a decent amount of RAM to work. - VioLet

1 answer 1

Try without including javascript. Everyone constantly complains about a memory leak when this feature is enabled.

  • Without including all the rules, but without JavaScript, I can’t, I didn’t optimize anything less, the application is still holding - ramin