diff --git a/Awful.apk/src/main/java/com/ferg/awfulapp/webview/AwfulWebView.java b/Awful.apk/src/main/java/com/ferg/awfulapp/webview/AwfulWebView.java index eddc3b230..a4418de89 100644 --- a/Awful.apk/src/main/java/com/ferg/awfulapp/webview/AwfulWebView.java +++ b/Awful.apk/src/main/java/com/ferg/awfulapp/webview/AwfulWebView.java @@ -116,6 +116,28 @@ public void onResume() { resumeTimers(); } + + /** + * Issue #562: the renderer process leaks when a WebView is dropped + * without an explicit destroy(), and the well-known fix is to + * detach from the parent first so Chromium can release its surface. + * Callers (fragments, activities) should invoke this from their + * own onDestroy() / onDestroyView(). + */ + public void release() { + if (jsInterface != null) { + removeJavascriptInterface(HANDLER_NAME_IN_JAVASCRIPT); + jsInterface = null; + } + loadUrl("about:blank"); + clearHistory(); + ViewGroup parent = (ViewGroup) getParent(); + if (parent != null) { + parent.removeView(this); + } + destroy(); + } + /** * Connects a handler to the JavaScript functions added to HTML for threads, posts, messages etc. *