title: What is the correct way to free large array memory
body: <p>I am working with image processing with canvas. </p>
  
  <p>Users will select 10 photos (normally large-resolution photos) each time, then a script will process these photos before uploading them to a server. </p>
  
  <p>The process will create large arrays and consumes lots of memory. So I am wondering <strong>which of the options listed below is the correct way to free memory</strong>.</p>
  
  <p><strong>option 1:</strong> do nothing, leave GC to handle the memory use </p>
  
  <pre class="lang-js prettyprint-override"><code>for(int i=0;i&lt;10;i++) {
      var bigArray = new Array(20000000);
      //do something with bigArray
  }
  </code></pre>
  
  <p><strong>option 2:</strong> set to null</p>
  
  <pre class="lang-js prettyprint-override"><code>for(int i=0;i&lt;10;i++) {
      var bigArray = new Array(20000000);
      //do something with bigArray
  
      bigArray=null;  
  }
  </code></pre>
  
  <p><strong>option 3:</strong> set to null after freeing array contents</p>
  
  <pre class="lang-js prettyprint-override"><code>for(int i=0;i&lt;10;i++) {
      var bigArray=new Array(20000000);
  
      //do something with bigArray
  
      bigArray=[];
      bigArray=null;  
  }
  </code></pre>
  
  <p><strong>option 4:</strong> set to null after setting array length to zero</p>
  
  <pre class="lang-js prettyprint-override"><code>for(int i=0;i&lt;10;i++) {
      var bigArray=new Array(20000000);
      //do something with bigArray
      bigArray.length=0;
      bigArray=null;  
  }
  </code></pre>