Skip to content

Commit

Permalink
Fix memory leak - initially reported in apache#290
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
leonardo-fernandes committed Dec 13, 2021
1 parent 9c9587c commit c1741ea
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c1741ea

Please sign in to comment.