WKWebView uses addScriptMessageHandler to cause memory leak

The interface that used WKWebView was not released. After investigation, it was found that it was [self.config.userContentController addScriptMessageHandler:self name:self.jsName];a ghost.
The userContentController here holds self, and then the userContentController is held by the configuration, and finally held by the webView, and then webView is a member variable of self, so self holds self, which causes a circular reference and causes the interface to not be released.

Solution:
addScriptMessageHandler
in viewWillAppear removeScriptMessageHandlerForName in viewWillDisappear
so that the memory is released.

Guess you like

Origin blog.csdn.net/qq_28285625/article/details/102700253