Skip to content Skip to sidebar Skip to footer

Webview Eating Up Too Much Memory

In my app there are two activities viz A and B. Activity A: It has a list which displays information about an item briefly. When an item on A is clicked, it loads Activity B. Activ

Solution 1:

I followed series of steps and got the memory footprint reduced. This is what I did, instead of creating webview statically via xml I now create webview programmatically and add it to a container. Once webview is no longer needed I remove the webview from the container then I remove all views from webview and call destroy on it. Eventually memory allocated reduces.

privatevoidreleaseWebView() {

    webViewContainerRelView.removeAllViews();
        if(mWebView != null){
            mWebView.setTag(null);          
            mWebView.clearHistory();
            mWebView.removeAllViews();          
            mWebView.clearView();
            mWebView.destroy();
            mWebView = null;
        }
}

I call releaseWebView() from onDetachedFromWindow method of Activity as below.

@Override
public void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    releaseWebViews();
}

Post a Comment for "Webview Eating Up Too Much Memory"