From c1741ea2308e9ef6bf4d634905eb148b6fe51dff Mon Sep 17 00:00:00 2001 From: Leonardo Monteiro Fernandes Date: Mon, 13 Dec 2021 12:26:09 +1000 Subject: [PATCH] Fix memory leak - initially reported in https://github.com/apache/cordova-plugin-inappbrowser/issues/290 Whenever closing an InAppBrowser instance, a webview was left in memory with about:blank page. This change fixes the issue by destroying and freeing the inAppWebView object. --- src/android/InAppBrowser.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index d141c0664..e73a75fcf 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -545,6 +545,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("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