From ed7a262197aebd39e39c98a04f367d675c0ad8a1 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 12 Aug 2024 20:20:43 -0700 Subject: [PATCH] fix: Fix memory leak from user script handler Closes #920. --- .../Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m b/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m index afba3ecc8b..2bda97077f 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m +++ b/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m @@ -273,6 +273,14 @@ - (void)pluginInitialize NSLog(@"Using WKWebView"); } +- (void)dispose +{ + WKWebView* wkWebView = (WKWebView*)_engineWebView; + [wkWebView.configuration.userContentController removeScriptMessageHandlerForName:CDV_BRIDGE_NAME]; + + [super dispose]; +} + - (void) onAppWillEnterForeground:(NSNotification*)notification { if ([self shouldReloadWebView]) { NSLog(@"%@", @"CDVWebViewEngine reloading!");