I'm rapidly capturing screenshots of a webpage loaded into a WKWebView. While working fine in the simulator when running on an iOS device each call to takeSnapshot seems to allocate unnecessary amounts of memory (70+ MiB).
Note that the total amount of allocated memory is way less when running in the sim.
I did not have this issue prior to upgrading to iOS 16. Is this something that is known to have changed?
Also, what does WKWebView base its allocated memory on? It doesn't seem to reduce by capturing smaller screenshots.
Thanks.
After further investigation each frame was 3x the size of the WKWebView, probably due to the device's resolution. This, in turn, allocated unnecessary amounts of memory, which was only partly affected of changing the size of the web view.
Fixing the size of the screenshot
The screenshot size can be set using the snapshotWidth property of WKSnapshotConfiguration.
let config = WKSnapshotConfiguration()
config.snapshotWidth = 1920
takeSnapshot(with: config) { (image, _) in
// Use image
}