title: Why does this javascript have a memory leak in Chrome?
body: <p>I have a timer function that creates a large amount of data, declared with var.  Why does the object not get garbage-collected?  The number shown by usedJSHeapSize keeps growing.  Task Manager in Chrome also shows memory increasing.</p>
  
  <p>I'm testing this in Windows 10, Chrome, using VS 2017. </p>
  
  <p>If I copy and paste the code into a separate file called test.html and open that in Chrome, it also shows the leak.  </p>
  
  <p>I've tested this code in Edge and IE (using Developer Tools instead of usedJSHeapSize) and I see no memory leak.</p>
  
  <p>Is this an issue with Chrome?</p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
          function refreshTimer() {
              try {
                  var longStr = new Array(1000000).join('*');
                  document.getElementById('div1').textContent = 'usedJSHeapSize: ' + window.performance.memory.usedJSHeapSize;
              }
              catch (err) {
                  document.getElementById('div1').textContent = 'refreshTimer: ' + err;
              }
          }
          window.setInterval("refreshTimer()", 3*1000);
      &lt;/script&gt;
      &lt;div id="div1" style="font-family:Calibri"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>I expect that there would be no memory leak because the large data object is declared with var and should be garbage-collected when it leaves scope.</p>
  
  <p>Edit to my my original post:</p>
  
  <p>I have run Chrome with and without "--enable-precise-memory-info" and it makes no difference.  I have observed memory growing in Chrome->More Tools->Task Manager and in Windows Task manager with just one instance of Chrome running with my test.html file.
  The only links I can find that mention this as a possible bug in Chrome are these:</p>
  
  <p><a href="https://stackoverflow.com/questions/12318103/javascript-garbage-collection-of-typed-arrays-in-chrome">Javascript garbage collection of typed arrays in Chrome</a></p>
  
  <p><a href="https://bugs.chromium.org/p/chromium/issues/detail?id=232415" rel="nofollow noreferrer">https://bugs.chromium.org/p/chromium/issues/detail?id=232415</a></p>
  
  <p>These are old posts though and I can't believe the bug would live this long.</p>
  
  <p>So - I'm still perplexed.</p>
  
  <p>1/2/2019 - adding a comment to move this question to the top of SO. If anyone knows, please add your thoughts.</p>