Bug 237652 - WKUserContentController.add(_:name:) leads to memory leak even if wrap the object into a weak reference wrapper
Summary: WKUserContentController.add(_:name:) leads to memory leak even if wrap the ob...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 15
Hardware: All iOS 15
: P2 Major
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-03-09 06:01 PST by Daohan Chong
Modified: 2022-05-16 08:42 PDT (History)
2 users (show)

See Also:


Attachments
Demo project (50.00 KB, application/x-gzip)
2022-03-10 06:05 PST, Daohan Chong
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daohan Chong 2022-03-09 06:01:00 PST
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).
Comment 1 Daohan Chong 2022-03-10 06:05:39 PST
Created attachment 454352 [details]
Demo project
Comment 2 Radar WebKit Bug Importer 2022-03-10 10:21:21 PST
<rdar://problem/90106783>
Comment 3 Daohan Chong 2022-03-18 01:49:23 PDT
Another example: https://stackoverflow.com/a/26383032/2949840