title: How to resolve memory leak in node.js due to .map function
body: <p>I am trying to export 9 million records from my mssql database to a mysql database using a node.js app </p>
  
  <p>I am running into a memory issue which I suspect is due to my map functions.( Bluebird Promise.map)</p>
  
  <p>The below Myfucntion() calls the doThis() function which gets a set of records from my Mssql database then insert the record into a MySql database.</p>
  
  <pre><code>Myfucntion(){
  Promise.map(ids, id =&gt; doThis(id).then(results =&gt; console.log(results)), { concurrency: 5});
  }
  
  const doThis = async (id) =&gt; {
    try{
         const results = await sql.query`select results where id = ${id}`;
          if((results &amp;&amp; results.recordset) &amp;&amp; results.recordset.length &gt; 0 ) {
            results.recordset.map(asset =&gt;  insertResultslAsset(convertResultAsset(asset)));
          }
    }
    catch(err){
        console.log(err)
    }
   };
  </code></pre>
  
  <p>The convertResultAsset(asset) function creates a 4 properties object before doing the inserts. </p>
  
  <p>I suspect the  memory leakage occurs because the converted assets are being stored incrementally in memory with the .map iterations</p>
  
  <p>I  was able to  alleviated the problem by running --max-old-space-size=20000 on the program.</p>
  
  <p>After I perform the inserts from the doThis() function there is no need for me to store the converted Assets.</p>
  
  <p>Is there a way to release these objects from the .map function?</p>