Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform centered approach: let's add a way to destroy a WKWebView when done #1486

Closed
msmtamburro opened this issue Sep 4, 2024 · 2 comments · Fixed by #1497
Closed

Platform centered approach: let's add a way to destroy a WKWebView when done #1486

msmtamburro opened this issue Sep 4, 2024 · 2 comments · Fixed by #1497
Milestone

Comments

@msmtamburro
Copy link
Contributor

Feature Request

Even though there is an attempt to "clear out" the WKWebView in the CDVViewController.m dealloc method, the WKWebView in CDVWebViewEngine.m is not simultaneously made nil, so it hangs around. I'd like to update these two classes to fully nil out WKWebView.

Motivation Behind Feature

In an otherwise native app that includes Cordova as a Swift Package to occasionally open Cordova Web Views for specific features (e.g., the Platform Centered Approach) it is common to open and close CDVViewControllers in the course of a user session, as a user navigates around. Because there is no exposed method to fully destroy a WKWebView, all of the web views opened hang around, increasing system memory footprint (albeit outside of the host app's process).

Feature Description

I will likely just call a new method in dealloc, or I could leave it up to a platform centered approach consumer to make the call--I want to think about it a bit. This shouldn't have any impact on the non-platform centered approach, and we use that as well, so it should be easy to test both.

Alternatives or Workarounds

It's possible to mimic some of what's done in dealloc, and "lighten" the WKWebView by loading an empty string and removing script message handlers, but it would be better to just kill it when done.

@dpogue
Copy link
Member

dpogue commented Sep 4, 2024

I think the fix would be to null out the webview in the plugin's dispose method, since that is called when tearing down the view controller

msmtamburro added a commit to msmtamburro/cordova-ios that referenced this issue Sep 4, 2024
msmtamburro added a commit to msmtamburro/cordova-ios that referenced this issue Sep 4, 2024
msmtamburro added a commit to msmtamburro/cordova-ios that referenced this issue Sep 4, 2024
msmtamburro added a commit to msmtamburro/cordova-ios that referenced this issue Sep 4, 2024
msmtamburro added a commit to msmtamburro/cordova-ios that referenced this issue Sep 6, 2024
msmtamburro added a commit to msmtamburro/cordova-ios that referenced this issue Sep 6, 2024
@dpogue dpogue added this to the 8.0.0 milestone Sep 9, 2024
msmtamburro added a commit to msmtamburro/cordova-ios that referenced this issue Oct 9, 2024
@msmtamburro
Copy link
Contributor Author

I think the fix would be to null out the webview in the plugin's dispose method, since that is called when tearing down the view controller

This indeed did the trick. Adding ‘_engineWebView = nil;’ right before the [super dispose]; call is the only change needed.

It will take some time for me to get permission to raise this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants