From our developer side, adding user script will unexpectedly leak the WKUserScript object even if the WKWebView instance is deallocated. Proof: https://twitter.com/WildCat_io/status/1501547346416799746 Workaround of this bug: To remove all message handlers when the WKWebView is deallocated: https://github.com/Lakr233/XTerminalUI/blob/3204296353e8874020c834cc70343f73ad4ecdf9/Sources%2FXTerminalUI%2FXTerminalWebViewDelegate.swift#L26 (It can also be put into WKWebView.deinit). It can be reproduced on both iOS 15 and macOS 12 (catalyst).
Created attachment 454352 [details] Demo project
<rdar://problem/90106783>
Another example: https://stackoverflow.com/a/26383032/2949840