Memory leak when using WKScriptMessageHandler

前端 未结 4 1019
别跟我提以往
别跟我提以往 2021-02-02 00:36

Not sure if I hit a bug in WebKit or I am doing something horribly wrong, but I can\'t figure out how to use WKScriptMessageHandler without causing wha

4条回答
  •  误落风尘
    2021-02-02 01:06

    I've encountered same problem on iOS 9 SDK.

    I noticed userContentController.addScriptMessageHandler(self, name: "handler") will keep the reference of the handler. To prevent leaks, simply remove the message handler when you no longer need it. e.g. when you dismiss the said controller, call a clean up method that will call removeScriptMessageHandlerForName().

    You might consider move the addScriptMessageHandler() to viewWillAppear and add a corresponding removeScriptMessageHandlerForName() calls in viewWillDisappear.

提交回复
热议问题