title: iOS safari WebGL memory leak in iframe
body: <p>Test environment: iPad6 iOS 14</p>
  <p>I have a sample html with a iframe in it.Each time the iframe switch from webgl page to blank,memory leak occurs.Repeat this safari will finally crash and reload.</p>
  <p>Safari memory usage can be seen from perfdog(perfdog.wetest.net).Note: filter process to &quot;com.apple.WebKit.WebContent&quot;.</p>
  <p>Memory leak log:
  <a href="https://i.stack.imgur.com/Tcrkf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tcrkf.jpg" alt="enter image description here" /></a></p>
  <p>Test iframe page:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
      &lt;style&gt;
          * {
              box-sizing: border-box;
          }
  
          /* Create two equal columns that floats next to each other */
          .column {
              float: left;
              width: 80%;
              padding: 10px;
              height: 600px;
              /* Should be removed. Only for demonstration */
          }
  
          .column2 {
              float: left;
              width: 20%;
              padding: 10px;
              height: 600px;
              /* Should be removed. Only for demonstration */
          }
  
          /* Clear floats after the columns */
          .row:after {
              content: &quot;&quot;;
  
              clear: both;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;script&gt;
          function htmlToElement(html) {
              var template = document.createElement('template');
              html = html.trim(); // Never return a text node of whitespace as the result
              template.innerHTML = html;
              return template.content.firstChild;
          }
  
          function createIframeIfNotExists() {
              let iframe = document.getElementById(&quot;iframe&quot;);
              if (!iframe) {
                  const deviceLostHtmlString = `
                      &lt;iframe id=&quot;iframe&quot; src=&quot;&quot; width=&quot;100%&quot; height=&quot;100%&quot; title=&quot;Iframe Example&quot;&gt;&lt;/iframe&gt;
                      `;
                  iframe = htmlToElement(deviceLostHtmlString);
                  document.getElementById(&quot;iframe_parent&quot;).appendChild(iframe);
              }
              return iframe;
          }
  
          function toWebgl() {
              createIframeIfNotExists().src = &quot;https://webglsamples.org/aquarium/aquarium.html&quot;;
          }
          function toBlank() {
              let iframe = document.getElementById(&quot;iframe&quot;);
              if (iframe) {
                  iframe.src = &quot;about:blank&quot;;
                  // iframe.contentWindow.document.write('');
                  // iframe.contentWindow.document.clear();
                  // iframe.parentNode.removeChild(iframe);
              }
          }
          function toGitee() {
              createIframeIfNotExists().src = &quot;https://gitee.com&quot;;
          }
      &lt;/script&gt;
  
      &lt;h2&gt;Two Equal Columns&lt;/h2&gt;
  
      &lt;div class=&quot;row&quot;&gt;
          &lt;div id=&quot;iframe_parent&quot; class=&quot;column&quot; style=&quot;background-color:#aaa;&quot;&gt;
              &lt;!-- &lt;iframe id=&quot;iframe&quot; src=&quot;&quot; width=&quot;100%&quot; height=&quot;100%&quot; title=&quot;Iframe Example&quot;&gt;&lt;/iframe&gt; --&gt;
          &lt;/div&gt;
          &lt;div class=&quot;column2&quot; style=&quot;background-color:#bbb;&quot;&gt;
              &lt;button onclick=&quot;toBlank()&quot;&gt;about:blank&lt;/button&gt;
              &lt;button onclick=&quot;toWebgl()&quot;&gt;WebGL sample&lt;/button&gt;
              &lt;button onclick=&quot;toGitee()&quot;&gt;gitee&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  <hr />
  <p>Update:</p>
  <p>Webkit bug report: <a href="https://bug.webkit.org/show_bug.cgi?id=218168" rel="nofollow noreferrer">https://bug.webkit.org/show_bug.cgi?id=218168</a></p>