Bug 215729 - Memory leak issue for WKWebView:evaluateJavaScript
Summary: Memory leak issue for WKWebView:evaluateJavaScript
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 13
Hardware: iPhone / iPad iOS 13
: P2 Critical
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-08-21 04:11 PDT by Michael Kreitmann
Modified: 2024-06-20 20:33 PDT (History)
8 users (show)

See Also:


Attachments
Xcode project to reproduce the issue (753.34 KB, application/zip)
2020-08-21 04:11 PDT, Michael Kreitmann
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Kreitmann 2020-08-21 04:11:04 PDT
Created attachment 407008 [details]
Xcode project to reproduce the issue

When calling evalueJavaScript function with a large String (i.e. a 100MB String) as show below, WebView will always hold a reference to this large string (allocating memory) and will not release the memory.

Executing this code several times, will cause WebKit task to crash (due to memory issues) and will restart.


__block NSString *script = [NSString stringWithFormat:@"//%@", [@"" stringByPaddingToLength:100*1024*1024 withString: @"?" startingAtIndex:0]];
[weakWebView evaluateJavaScript:script completionHandler:nil];

See attached Xcode project to reproduce the issue.
Comment 1 Radar WebKit Bug Importer 2020-08-22 16:11:20 PDT
<rdar://problem/67625708>
Comment 2 Danesz 2021-11-16 12:29:35 PST
Unfortunately the problem is still present, so I have implemented a PoC to overcome this issue.

https://github.com/Danesz/Sidewalk

Sidewalk is available as a Swift package.


Also a sample app with the proof of the leak:
https://github.com/Danesz/SidewalkExample
Comment 3 Eric Slosser 2023-01-10 11:54:15 PST
seems fixed in iOS 16.2
Comment 4 Palaneappan K Rajalingam 2024-06-20 20:33:00 PDT
This issue still exists. I am able to reproduce the similar issue in safari browser. However, the memory issue doesn't occur in other web browsers though.