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

[Bug]: BridgeFragment doesn't call WebView.destroy in Fragment.onDestroy() #7766

Closed
1 of 3 tasks
hbordersTwitch opened this issue Nov 19, 2024 · 4 comments
Closed
1 of 3 tasks
Labels

Comments

@hbordersTwitch
Copy link

Capacitor Version

[warn] The bundledWebRuntime configuration option has been deprecated. Can be safely deleted.
💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 6.1.1
@capacitor/core: 6.1.1
@capacitor/android: 6.1.1
@capacitor/ios: 6.1.1

Installed Dependencies:

@capacitor/cli: 6.1.1
@capacitor/ios: 6.1.1
@capacitor/android: 6.1.1
@capacitor/core: 6.1.1

[success] iOS looking great! 👌
[success] Android looking great! 👌

Other API Details

$ npm --version
10.7.0
$ node --version
v22.2.0
$ pod --version
1.15.2

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

BridgeFragment.onDestroy() calls Bridge.onDestroy(), but Bridge.onDestroy() does not call WebView.destroy().

This matters because if we don't call WebView.onDestroy(), the WebView leaks its WebMessageListener instances. Capacitor's WebMessageListener holds a references to the CapacitorWebView, which holds a reference to the Bridge, which holds a reference to the BridgeFragment.

Expected Behavior

After BridgeFragment.onDestroy(), Capacitor cleans up all resources

Project Reproduction

Please let me know if you require a repro for this.

Additional Information

One can work around this by extending BridgeFragment.onDestroy() and calling bridge.getWebView().destroy() manually.

Thank you for this project!

@jcesarmobile
Copy link
Member

Thanks for the issue, but we are removing BridgeFragment on Capacitor 7 since is not something Capacitor apps use.

If you are using it, we would recommend to just copy the BridgeFragment class into your project or inside a plugin and use that one instead of the one inside Capacitor as it will go away, and then apply any changes you need like calling WebView.destroy().
I've verified that BridgeFragment doesn't use any Capacitor's private or protected attributes/classes, so can be recreated outside of Capacitor if needed.

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Dec 4, 2024
@hbordersTwitch
Copy link
Author

Just to double-check, are you planning to do a similar deprecation of CAPBridgeViewController?

@jcesarmobile
Copy link
Member

jcesarmobile commented Dec 5, 2024

No, CAPBridgeViewController is used by all Capacitor iOS apps, is the BridgeActivity equivalent.
For iOS we already removed CAPWebView class in Capacitor 6, which was sort of the BridgeFragment equivalent.

Copy link

ionitron-bot bot commented Jan 4, 2025

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jan 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants