0

I load website which loads whole page using Javascript files to WebView. Every time when I load page to Web view it shows me some memory increased in

setting > apps > running

Even, when I release Webview then also it does not release the memory.

I am not caching the resources in Webview. But, when I used instruments to analyse the memory , it shows me images resources are cached in memory which does not get released. My code is here for ref :

    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);
    Intent in = getIntent();
    String page_url = in.getStringExtra("link");
    Log.i("display","url :"+page_url);
    if(deleteDatabase("webview.db") && deleteDatabase("webviewCache.db")){
        Toast.makeText(this, "Delete Webvie data base successfully",Toast.LENGTH_SHORT).show();
    }
    webview = (WebView) findViewById(R.id.webpage);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setWebViewClient(new WebViewClient());
    webview.getSettings().setLoadWithOverviewMode(true);
    webview.getSettings().setAppCacheEnabled(false);
    webview.loadUrl(page_url);
    webview.clearHistory();
    webview.clearFormData();
    webview.clearCache(true);

Can anyone please guide me where I am missing? How can I optimize the memory loading to WebView?

Thanks in advance.

AndyBoy
  • 564
  • 6
  • 29
  • according to android documentation it's not in your hand to end an application, it'll be swapped out from memory after a while when its not been used so don't worry about memory issue android system is proficient enough to handle memory itself – Nitin Misra Nov 18 '13 at 08:50
  • its consuming 33 Mbs for this simple aplication.. its showing me memory leak from somewhere i dont know where. – AndyBoy Nov 18 '13 at 08:52
  • is your application crashing? the number of Mbs does depends on the webpage you're loading in webview, more the number of images more it require memory. – Nitin Misra Nov 18 '13 at 08:54
  • no more images in webview. memory increase after click on listview(which stores the url). – AndyBoy Nov 18 '13 at 08:56

1 Answers1

1

WebView is a complex UI widget and will consume significant memory whilst in use. Prior to Andriod 4.4, the WebView.freeMemory() API may help, depending on what is actually using the memory behind the scenes.

Some memory will be reclaimed when you are finished with the WebView and invoke WebView.destroy() and detach it from the view hierarchy.

In Android 4.4 memory management is more automatic inside the WebView and the WebView will attempt to free up memory when the system is under load and triggers onTrimMemory (http://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory(int)).

ksasq
  • 4,424
  • 2
  • 18
  • 10