My view controller displays a WKWebView. I installed a message handler, a cool Web Kit feature that allows my code to be notified from inside the web page:
o
The leak is caused by userContentController.addScriptMessageHandler(self, name: "handlerName") which will keep a reference to the message handler self.
To prevent leaks, simply remove the message handler via userContentController.removeScriptMessageHandlerForName("handlerName") when you no longer need it. If you add the addScriptMessageHandler at viewDidAppear, its a good idea to remove it in viewDidDisappear.