<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>194268</bug_id>
          
          <creation_ts>2019-02-04 18:40:39 -0800</creation_ts>
          <short_desc>Safari does not free ArrayBuffers being transferred from webworker to main thread</short_desc>
          <delta_ts>2020-01-08 12:17:00 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>Safari 12</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 12</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=172790</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=203990</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Critical</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Sanjay Kumar">hypertree</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cdumez</cc>
    
    <cc>dino</cc>
    
    <cc>keith_miller</cc>
    
    <cc>lee</cc>
    
    <cc>mike</cc>
    
    <cc>rniwa</cc>
    
    <cc>saam</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
    
    <cc>zac.spitzer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1502200</commentid>
    <comment_count>0</comment_count>
    <who name="Sanjay Kumar">hypertree</who>
    <bug_when>2019-02-04 18:40:39 -0800</bug_when>
    <thetext>Safari frequently runs out of memory running webapps using WebGL libraries such as Mapbox GL-JS and Tangram that transfer large number of araybuffers from webworker to main thread.

This was previously reviewed here and mistakenly marked as RESOLVED/WORKSFORME:
https://bugs.webkit.org/show_bug.cgi?id=172790#c10

Mapbox engineer has provided a small example that clearly shows Safari memory usage growing indefinitely as Safari never garbage collects ArrayBuffrs allocated in the webworker and transferred to foreground thread. Example can be found here (plain simple few lines of JavaScript, no WebGL):
https://measuredweighed.github.io/mapboxgl-js-mem-usage/arraybuffer-test.html

This example also crashes Firefox but rcent version of Chrome is able to garbage collect and keep memory usage down to 1 GB.

Apparently such transfer of arraybuffers is core to WbeGL applications and expected to work.

Safari users of my app have suffered for years and it impossible to release our App for iOS without this issue being fixed.

It seems end is in sight since core issue has been identified.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1502408</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-02-05 10:02:26 -0800</bug_when>
    <thetext>&lt;rdar://problem/47821447&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1521586</commentid>
    <comment_count>2</comment_count>
    <who name="kleggerkoder">mike</who>
    <bug_when>2019-03-26 18:52:52 -0700</bug_when>
    <thetext>Any timelines on this bug fix?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1523513</commentid>
    <comment_count>3</comment_count>
    <who name="Dean Jackson">dino</who>
    <bug_when>2019-04-02 16:35:12 -0700</bug_when>
    <thetext>Taking a look at this now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1524104</commentid>
    <comment_count>4</comment_count>
    <who name="Dean Jackson">dino</who>
    <bug_when>2019-04-03 19:02:40 -0700</bug_when>
    <thetext>I spent a fair bit of time on this and think the issue is fixed, at least on tip-of-tree.

Attached two test cases I made (modifications to the one linked above). They allocate some ArrayBuffers in the worker, and then transfer them to the main thread via postMessage. The main thread only keeps references to a small number of buffers.

The allocation timeline in the Web Inspector shows garbage collection triggering, and only a fixed number of ArrayBuffers being retained (the ones I&apos;m keeping a reference to).

I also tried with Instruments and the Allocations widget. It also showed that while a large number of ArrayBuffers were created, they were all reclaimed over time.

Lastly I put printf statements in JavaScriptCore for ArrayBuffer&apos;s constructor and destructor. Each of the large ArrayBuffers allocated in the Worker was eventually reclaimed (and very soon after the references were dropped, because they were taking up a lot of memory).

[Side note: I was not sure if it should be &quot;each... was&quot; or &quot;each were&quot;. Most resources say &quot;was&quot; (s), but many say &quot;were&quot; (pl) is acceptable too.]</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1524105</commentid>
    <comment_count>5</comment_count>
      <attachid>366692</attachid>
    <who name="Dean Jackson">dino</who>
    <bug_when>2019-04-03 19:03:05 -0700</bug_when>
    <thetext>Created attachment 366692
tests</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1524107</commentid>
    <comment_count>6</comment_count>
    <who name="Dean Jackson">dino</who>
    <bug_when>2019-04-03 19:05:16 -0700</bug_when>
    <thetext>I also tried the original test with my printf statements and confirmed that the ArrayBuffers are being deallocated.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1524192</commentid>
    <comment_count>7</comment_count>
    <who name="Sanjay Kumar">hypertree</who>
    <bug_when>2019-04-04 04:38:07 -0700</bug_when>
    <thetext>It seems fix was included in ios 12.2 because when I tested a few weeks back my Web App was no longer crashing even if I left it running for extended time. Earlier it would crash in 5-10 minutes on low memory devices.

This is great news and great relief to all of us WebGL users and Mapbox users - we can think of iOS now as a viable platform for Web Apps thanks to this fix. Thank you Apple/Webkit team !</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1524406</commentid>
    <comment_count>8</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2019-04-04 13:41:09 -0700</bug_when>
    <thetext>(In reply to Sanjay Kumar from comment #7)
&gt; It seems fix was included in ios 12.2 because when I tested a few weeks back
&gt; my Web App was no longer crashing even if I left it running for extended
&gt; time. Earlier it would crash in 5-10 minutes on low memory devices.

That&apos;s great!

&gt; This is great news and great relief to all of us WebGL users and Mapbox
&gt; users - we can think of iOS now as a viable platform for Web Apps thanks to
&gt; this fix. Thank you Apple/Webkit team !

Thank YOU for reporting the issue you saw. We always appreciate good bug reports on our products :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1537470</commentid>
    <comment_count>9</comment_count>
    <who name="Sanjay Kumar">hypertree</who>
    <bug_when>2019-05-19 02:40:57 -0700</bug_when>
    <thetext>I am sorry but the problem is back in iOS 12.3. 

test is still available @:
https://measuredweighed.github.io/mapboxgl-js-mem-usage/arraybuffer-test.html

If you run the test for a few minutes on an IPAD 5 with 2 GB RAM and iOS 12.3 the page crashes in seconds. memory usage grows quickly and iOS Safari kills the web page almost immediately. Test does not crash on my iPhone 8 plus w/ iOS version 12.2. It also does not crash on Safari Technology Preview 81 or version 82 on High Sierra.

So something went wrong in iOS 12.3. Please fix. Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1558289</commentid>
    <comment_count>10</comment_count>
    <who name="Sanjay Kumar">hypertree</who>
    <bug_when>2019-08-03 09:22:31 -0700</bug_when>
    <thetext>I checked further. It seems crash I am seeing does not have to do this with specific bug which indeed seems fixed. It seems Safari has some general limit of overall memory use and we are running into that due to memory bloat.

So I am marking this bug as fixed and opening a new bug for Mapbox. Since I am seeing crashes only on iOS Safari so it may still have to do with webkit but probably its not this bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1558438</commentid>
    <comment_count>11</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2019-08-05 00:40:00 -0700</bug_when>
    <thetext>Thanks for the follow up!</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>366692</attachid>
            <date>2019-04-03 19:03:05 -0700</date>
            <delta_ts>2019-04-03 19:03:05 -0700</delta_ts>
            <desc>tests</desc>
            <filename>arraybuffer-worker.zip</filename>
            <type>application/zip</type>
            <size>2174</size>
            <attacher name="Dean Jackson">dino</attacher>
            
              <data encoding="base64">UEsDBAoAAAAAAKpmhE4AAAAAAAAAAAAAAAATABwAYXJyYXlidWZmZXItd29ya2VyL1VUCQADj2Ol
XJBjpVx1eAsAAQT1AQAABBQAAABQSwMEFAAAAAgAoV6ETkK95E9JAQAAegIAABwAHABhcnJheWJ1
ZmZlci13b3JrZXIvd29ya2VyLmpzVVQJAANtVaVcbVWlXHV4CwABBPUBAAAEFAAAAHVQsWrDMBDd
/RWHJ6dOTVI6hLgpdMjUlhRD2yFkkO2zIypLQZITQvC/9xTbRVByg2S/u3d67xVKGgt5W1Wo31DW
dg8rmM8eHu+uxyINCm/CfKB+R2NYjTRGzUCghaLVGqX9YqJ18JxgJZu/saqVheVKRjiBSwBUbqUS
mAhVR+H3JntdZ0vQWCA/YgkDcwkhxIBJySxLGlNP0iv3yPQohnZvdz1aKQ2R08IJnKV0Pf2XTHAc
jxpcOUJOBIkn+OTSLl60ZufIT2N41VW+ne1o2Hcbx167fy45tGYf5Un/O9C727YNypLLenQNVkHD
uAwHpkFRJQdl7OAhulAUFM0ehVBQadXASekf1OHU7bekbDlK6abjFy0LfI0U15oVJBNWz14evAKn
/GxxMO/1bhpYZ9kmg/thN5S8BKksWM2kISD0Euxj6Ajp0uAXUEsDBBQAAAAIAHVkhE4WiGI7ewIA
AOIFAAAiABwAYXJyYXlidWZmZXItd29ya2VyL21haW4tbG9vcHMuaHRtbFVUCQADbV+lXG1fpVx1
eAsAAQT1AQAABBQAAACFVG1r2zAQ/u5fcQ2FOLRzMtiHkjqGbutgH7qOtaOMUqhqn2OttmQkuSGE
/PedLDlx3WwzBsv38ujuuUeKjz5ff7r99f0SClOVSRB3H2RZEgA9cYWGQVowpdEsxo3J352NYeqd
hpsSkwul2Ppjk+eooMJKqjU0mi0RDGoTT11QEE8davwks3USBLcF11DbMF2zldCQy0bBnVTPqHQE
dwUKMAV5DVMGnhpjpACbolBrzE5bZ8W4jVKEHD+p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