WKWebView memory issue causes crash

My app has a WKWebView which loads the certain HTML, CSS and JavaScript files. When the WKWebView is opened and files load initially, the memory usage of my app remains relatively low. If I start to use the application, in some time (5 mins) the total system free memory drops drastically and reloads the app. At that point the WKWebView reloads itself; there is no console message, no crash log, nothing. At most I'll see an Xcode message about my device having "BKSProcessAssertion 'ConnectionTerminationWatchdog' initialized with invalid pid".

The WKWebView has the markings of a memory leak and even if I remove the variables or objects their memory sticks around.

Is there some way to release any memory it's holding in order to avoid reloads of the app?
Use Instruments to check the memory usage of your app using the Memory or Leaks tools. Fix any leaks that you find.

If your app isn't consuming the memory, then try loading your HTML content in MobileSafari to see if (roughly) the same issue with the system getting low on memory occurs. If you can reproduce the low memory conditions just loading your HTML content in MobileSafari, you should file a Feedback Assistant bug, or file a bug on bugs.webkit.org and post the ID of either here. Make sure to include sample content that reproduces the low memory conditions on either a Feedback Assistant or bugs.webkit.org bug.

If your app or the com.apple.WebKit.WebContent process is getting killed for using too much memory, you will see a "JetsamEvent" log created on the device (assuming there aren't already 25 logs created today). If there are already 25 JetsamEvent logs on the device, sync them all off (to your Mac) so that new ones are created when you reproduce the issue.

I came through the same issue.

Apparently this is a reported bug in WebKit. https://bugs.webkit.org/show_bug.cgi?id=215729 My investigation result shows the same: https://github.com/Danesz/SidewalkExample

I have built a solution to overcome the problem. It is still in a proof-of-concept phase, missing some elements, but take a look on it: https://github.com/Danesz/Sidewalk Maybe it is good enough for your use-case. (and you can extend it anytime you want)

WKWebView memory issue causes crash
 
 
Q