ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚑️
https://capacitorjs.com
MIT License
12.29k stars 1.01k forks source link

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

Open hbordersTwitch opened 1 week ago

hbordersTwitch commented 1 week ago

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

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!