title: Javascript/Node.js array memory management
body: <p>I have a scene of use array as a queue, and I have a question of this scene about the memory.</p>
  
  <p>First, I create a array object in global, and create a producer to push the element to array uninterruptly.</p>
  
  <pre><code>var arr = [];
  
  function runningProducer() {
    setInterval(itemProducer, 50);
  
    function itemProducer() {
      var item = generateItem();
      arr.push(item);
    }
    function generateItem() {
      return { a: Math.random(), };
    }
  }
  </code></pre>
  
  <p>Then, I create a customer to clear the array in 1 second</p>
  
  <pre><code>function runningCustomer() {
    setInterval(clearQueue, 1000);
  
    function clearQueue() {
      var t = arr.concat(arr);
      arr = [];
    }
  }
  </code></pre>
  
  <p>And running the above functions for a period of time, I found the memory always growing.</p>
  
  <pre><code>setInterval(() =&gt; {
    var mem = process.memoryUsage();
    console.log(mem);
  }, 2000);
  </code></pre>
  
  <p>I think the array should release the memory after set empty, but not.
  Please give me some suggetions about this question, and is there any way to release the memory manually in javascript?</p>