Bug 229825 - Memory Leak when using createImageBitmap() in Safari 15 (iOS)
Summary: Memory Leak when using createImageBitmap() in Safari 15 (iOS)
Status: ASSIGNED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: Safari Technology Preview
Hardware: iPhone / iPad Other
: P2 Major
Assignee: Kimmo Kinnunen
URL:
Keywords: InRadar
Depends on: 187964 232139
Blocks:
  Show dependency treegraph
 
Reported: 2021-09-02 12:54 PDT by Wayne Langman
Modified: 2022-01-28 01:59 PST (History)
7 users (show)

See Also:


Attachments
Code and Screenshots (157.81 KB, application/zip)
2021-09-02 12:54 PDT, Wayne Langman
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wayne Langman 2021-09-02 12:54:04 PDT
Created attachment 437185 [details]
Code and Screenshots

While testing some of our games in iOS 15 (including the latest beta 8) we encountered some strange behaviour that I've narrowed down to createImageBitmap().

I've investigated this in Instruments, on an iPhone 7 and an iPhone 12, and it appears that the textures aren't being released from memory, which affects not only the current tab but all browser tabs (see the screenshot provided).

Please see the sample code provided which reproduces this issue.

The code will load 30x 2k textures via createImageBitmap(). Depending on your device and how much memory it has, if you open up another 1/2 tabs and load the same demo, and/or continuously refresh, you'll start to notice the occasional flicker of missing, or sometimes black, textures and eventually the tab crashes. Also, whether uploading 1 texture per animation frame or staggered over longer periods the result is the same.

This can be reproduced using the default experimental features but when disabling the canvas rendering process it behaves a little differently (from what I can tell). It may appear at first to resolve the issue but in fact only alleviates the missing/black textures and still leaks memory, eventually crashes the tab.

In our engine we use createImageBitmap() for supported browsers and otherwise use a polyfill (e.g. previous releases of Safari). In the meantime we've implemented a workaround to bypass this on iOS and always fall back to the polyfill. The sample code includes this fallback and does not display any of these issues.

On a side note: I see that createImageBitmap() was added to Safar 11 Technical Preview in November 2017 but am I correct in assuming that it has never actually made its way into release?
Comment 1 Wayne Langman 2021-09-02 13:08:22 PDT
Actually, in addition to my side note, is this even going to land in the Safari 15 release?
Comment 2 Wayne Langman 2021-09-02 13:22:47 PDT
And I just realised that there is a toggle for ImageBitmap under experimental features ...
Comment 3 Radar WebKit Bug Importer 2021-09-02 16:10:46 PDT
<rdar://problem/82697675>
Comment 4 Dean Jackson 2021-09-02 16:11:09 PDT
Thanks for the test case and detailed report!