Total canvas memory use exceeds the maximum limit (Safari 12)

后端 未结 8 1488
栀梦
栀梦 2020-12-05 10:21

We are working on a visualization web application which use d3-force to draw a network on a canvas.

But now we’ve got a problem with browsers on iOS, where the proces

相关标签:
8条回答
  • 2020-12-05 10:47

    I spent the weekend making a simple web page that can quickly show the problem. I have submitted bug reports to Google and Apple. The page brings up a map. You can pan and zoom all you want, and the Safari inspector (running web on iPad, using MacBook Pro to see the canvases) see no canvas.

    You can then tap a button and draw one polyline. When you do that, you see 41 canvases. Pan or zoom, and you'll see more. Each canvas is 1MB, so after you have 256 of the orphaned canvases, errors start as the canvas memory on the iPad is full.

    Reload the page, tap a button to place one polygon, and the same thing happens.

    Equally interesting is I added buttons to style the map for day and night. You can go back and forth when it's just a map (or a map with only markers, there is a button to display some markers on the map). No orphaned canvases. But draw a line, and then when you change the styling, you see more orphaned canvases.

    Looking at Safari on the MacBook in the Active Monitor, the size just keeps going as you pan and zoom around the map after drawing a poly*

    I hope Apple and Google can figure it out and not claim that it is the other company's problem. All this changed with IOS12 running web pages that have been stable for years, and that still work on IOS 9 and 10 iPads I keep for testing to be sure that older devices can show the current web pages. Hope this test/experiment helps.

    0 讨论(0)
  • 2020-12-05 10:47

    I can confirm this problem. No change to existing code that worked for years. However, in my case, the canvas is drawn only once when the page is loaded. Users can then browse between different canvases and the browser does a page reload.

    My debugging attempts so far show that Safari 12 apparently leaks memory between page reloads. Profiling memory consumption via Web Inspector shows that the memory keeps growing for each page reload. Chrome and Firefox on the other hand seem to keep memory consumption at the same level.

    From a user perspective, it helps to simply wait 20-30 seconds and do a page reload. Safari clears memory in the meantime.

    Edit: Here's a minimal proof of concept that shows how Safari 12 leaks memory between page loads.

    01.html

    <a href="02.html">02</a>
    <canvas id="test" width="10000" height="1000"></canvas>
    <script>
    var canvas = document.getElementById("test");
    var ctx = canvas.getContext("2d");
    ctx.fillStyle = "#0000ff";
    ctx.fillRect(0,0,10000,1000);
    </script>
    

    02.html

    <a href="01.html">01</a>
    <canvas id="test" width="10000" height="1000"></canvas>
    <script>
    var canvas = document.getElementById("test");
    var ctx = canvas.getContext("2d");
    ctx.fillStyle = "#00FF00";
    ctx.fillRect(0,0,10000,1000);
    </script>
    

    Steps to reproduce:

    • Upload both files to a webserver
    • Click the link on top repeatedly to switch between pages
    • Watch Web Inspector memory consumption go up for every page load

    I submitted a bug report to Apple. Will see how this works out.

    Edit: I updated the dimensions of the Canvas to 10000x1000 as a better proof of concept. If you now upload both files to a server and run it on your iOS device, if you rapidly switch between pages, the Canvas won't be drawn after several page reloads. If you then wait 30-60 seconds, some cache seems to be getting cleared and a reload will again show the Canvas.

    0 讨论(0)
提交回复
热议问题