Memory leak issue for WKWebView:evaluateJavaScript:completionHandler

Number:rdar://49722601 Date Originated:2019-04-09
Status:Open Resolved:NO
Product:WKWebview Product Version:iOS 12.2
Classification:Bug Reproducible:YES


In WKWebView:evaluateJavaScript:completionHandler call, if the javascript has a large str parameter, the WebView will always hold a reference to this large str after evaluateJavaScript execution. Although you set null to str parameter in javascript code, there will not release memory of str parameter forever.
That means WebView context will leak memory.

Steps to Reproduce:
Demo project is here,
Code summary:
`objective c

NSString *content = '*******';// content is a large str,  for example, which length is 1024*1024 * 100 bytes. In megabyte, it is a variable of 100 M size.

[self.webView evaluateJavaScript:[NSString stringWithFormat:@"window.onReceived('%@')", content] completionHandler:nil]
In webview  side,  it consume 99M javascript memory which will not be released. The image is here

Expected Results:
After window.onReceived execution, the memory of large str is released automatically by webview

Actual Results:
The webview hold memory forever that leads to leak issue. If the large str is big big content, the iOS system  may kill app totally for memory exhaust.

iOS SDK 12.2


Is this reproducible in iSO 13+? I'm also facing WKWebView causing app crash over a period on loading web content

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!