Closed j-crosson closed 2 months ago
I use a subclass of CDVViewController with a NavigationController and observed that removing CDVViewController from NavigationController results in not calling dealloc because of strong references. I had to remove the strong references such as the MessageHandler in viewWillDisappear so dealloc got called. In short: I copied the whole code of dealloc to viewWillDisappear including the above fix. That fixed the leak of CDVViewController in my case.
Bug Report
Problem
What is expected to happen?
No leak
What does actually happen?
leak
Information
I’m working on a plugin that uses a subclassed CDVViewController in a modal view. Works fine except for leaking CDVWebViewWeakScriptMessageHandler every time the view goes away. I was able to stop the leak with the following change to CDVViewController.m.
(void)dealloc { . . .
WKWebView wkWebView = (WKWebView)self.webViewEngine.engineWebView; [wkWebView.configuration.userContentController removeScriptMessageHandlerForName:(@"cordova")]; //CDV_BRIDGE_NAME
self.webViewEngine = nil; }
Not that this is the final fix, but it does point out the issue.
In my plugin subclass I use this:
The ordering is a bit different, but it seems to work.
This would also be an issue when embedding Cordova WebViews in a native app.
A related issue stems from the integration of the SplashScreen plugin into CDVViewController. I’m showing a non-startup view and don’t want to see a startup image (a Webview embedded in a native app would have the same issue) In my subclassed ViewController “viewDidLoad”, I replace “launchView” with a UIVIew with a selectable background color. No flashes or startup images show. Works fine. My issue is that I have to use techniques I’d rather not use to expose “private” class members
Command or Code
Environment, Platform, Device
iOS 13.5.1
Version information
Cordova v9 Cordova-ios 6.1.0 Xcode 11.5 macOS 10.15.5
Checklist