Skip to content

Instantly share code, notes, and snippets.

@dzwillpower
Created June 8, 2016 06:29
Show Gist options
  • Save dzwillpower/b0aa4ca26cd2314223bd553d3c7a3577 to your computer and use it in GitHub Desktop.
Save dzwillpower/b0aa4ca26cd2314223bd553d3c7a3577 to your computer and use it in GitHub Desktop.
destroy webbiew avoid memory leak
public void destroyAll() {
for (WebView webview : mWebViews) {
if (webview != null) {
webview.onPause();
webview.stopLoading();
webview.setWebViewClient(null);
webview.removeAllViews();
webview.clearHistory();
webview.clearCache(true);
webview.destroy();
ViewParent parent = webview.getParent();
if (parent != null && parent instanceof ViewGroup) {
ViewGroup oldParent = (ViewGroup) parent;
oldParent.removeView(webview);
}
webview = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment