Memory leak issue for WKWebView:evaluateJavaScript:completionHandler
Originator: | IamHite | ||
Number: | rdar://49722601 | Date Originated: | 2019-04-09 |
Status: | Open | Resolved: | NO |
Product: | WKWebview | Product Version: | iOS 12.2 |
Classification: | Bug | Reproducible: | YES |
Area: WebKit Summary: 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, git@github.com:hite/MessageHandlerIOLimitTest.git. 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 https://upload-images.jianshu.io/upload_images/277783-cc2e7e082a4d7b57.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000 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. Version/Build: iOS SDK 12.2
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com 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!
Is this reproducible in iSO 13+? I'm also facing WKWebView causing app crash over a period on loading web content