From ae0d8f6124fc6262ac914248937bff982ae8ff0d Mon Sep 17 00:00:00 2001 From: Jean Souza Date: Mon, 8 Nov 2021 10:25:01 -0300 Subject: [PATCH] fix(android): Fix for webView window not being destroyed correctly causing memory leak (bug #290) --- src/android/InAppBrowser.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 9a9fc7a8f..e9dd7a1b5 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -534,6 +534,16 @@ public void onPageFinished(WebView view, String url) { dialog.dismiss(); dialog = null; } + + // Fix for webView window not being destroyed correctly causing memory leak + // (https://github.com/apache/cordova-plugin-inappbrowser/issues/290) + if (url.equals(new String("about:blank"))) { + inAppWebView.onPause(); + inAppWebView.removeAllViews(); + inAppWebView.destroyDrawingCache(); + inAppWebView.destroy(); + inAppWebView = null; + } } }); // NB: From SDK 19: "If you call methods on WebView from any thread