title: Memory Leaks in Typescript when using Promises
body: <p>Having this piece of code in Typescript</p>
  
  <pre><code>const f = async function() {
      return 1+1;
  };
  
  let memory = process.memoryUsage();
  let i = 0;
  while (i &lt; 100000) {
      let result = await f().then(function(res) {}).catch(function() {});
      i++;
  }
  let memory2 = process.memoryUsage();
  console.log(memory2.heapUsed - memory.heapUsed);
  </code></pre>
  
  <p>The more iterations I make, the bigger is the heapUsed between both points.</p>
  
  <p>By reducing the method properly, and not using promises but a simple method, the heap used turns stable and doesn't change even if I iterate 1 milion times.</p>
  
  <pre><code>const f = function() {
      return 1+1;
  };
  
  let memory = process.memoryUsage();
  let i = 0;
  while (i &lt; 200000) {
      let r = f();
      i++;
  }
  let memory2 = process.memoryUsage();
  console.log(memory2.heapUsed - memory.heapUsed);
  </code></pre>
  
  <p>Can anyone explain a little bit where is exactly the memory leak here? Where is the point where something stays in memory ad eternum?</p>