0

I've read various posts here & tried using all the tips, but it still fails. Every instance of the app keeps accumulating more memory. Here's the code snippet. Any thoughts? Just using WebView to launch a page...

private class MyWV extends WebViewClient
{
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) 
        {
                Log.d("MyWV", "shouldOverrideUrlLoading, url = " +url);
                return false;
        }
}

@Override
public void onCreate(Bundle icicle) {
    Log.d(TAG, "onCreate");
    Toast.makeText(getApplicationContext(), "Please wait...", Toast.LENGTH_LONG).show();

    super.onCreate(icicle);
    setContentView(R.layout.main);

    mFL = (FrameLayout) findViewById(R.id.base_layout);

    mWebView = new WebView(this);
    mFL.addView(mWebView);

    mWebView.setWebViewClient(new MyWV());

    Log.e(TAG,"onCreate: Calling setJavaScriptEnabled...");
    mWebView.getSettings().setJavaScriptEnabled(true);

    mWebView.loadUrl("http://www.yahoo.com");
}

@Override
protected void onDestroy() {
    Log.d(TAG, "onDestroy");

    mFL.removeAllViews();

    mWebView.removeAllViews();
    mWebView.clearHistory();
    mWebView.loadUrl("about:blank");
    mWebView.freeMemory();
    mWebView.destroy();
    mWebView = null;

    super.onDestroy();
}
droid_dev
  • 303
  • 4
  • 15
  • Anyway remember onDestroy is called (not always called ) when the application finish "forever" (killed by os) not when, example, the screen rotate (onCreate is called in this case) – Marco Acierno Mar 07 '14 at 22:19

2 Answers2

0

As per Memory leak in WebView, try creating the WebView using the application context:

mWebView = new WebView(getApplicationContext());
Community
  • 1
  • 1
Squatting Bear
  • 1,644
  • 14
  • 12
  • I have tried this, doesn't help. Also, OnDestroy() is called every time I quit the app – droid_dev Mar 07 '14 at 22:34
  • It could also be this: http://code.google.com/p/android/issues/detail?id=9375, which is also referenced in http://stackoverflow.com/a/13618419/2020210 with a possible (though ugly) workaround. – Squatting Bear Mar 07 '14 at 22:52
-3

After lot of debugging, found that it's got nothing to do with Linux memory. It was something that we messed up in our graphics heap management. Found a fix & life's normal now

droid_dev
  • 303
  • 4
  • 15