title: Javascript: Out of Memory
body: <p>I'm working on a script that fetches and then parses a large amount of XML documents. The relevant part of the code is shown below. (URL has been hidden for privacy. The asterisks in the code are not actually there, they are used for reference later in the question)
  <br> <br></p>
  
  <pre><code>var xmlhttp = new XMLHttpRequest();
  var xmlDoc;
  var chunk = parseInt(1, 10);
  var subChunk = parseInt(0, 10);
  var indvCount = parseInt(0, 10);
  var total = parseInt(0, 10);
  var max = parseInt(5000, 10);
  var end = parseInt(chunk, 10) * parseInt(20, 10);
  var start = parseInt(end, 10) - parseInt(19, 10);
  
  function loadXML() {
  
  xmlhttp.abort();
  *xmlhttp.open("GET", "URL-GOES-HERE?start=" + start + "&amp;end=" + end, false);
  xmlhttp.setRequestHeader('Content-Type', 'text/xml', 'Pragma', 'no-cache');
  xmlhttp.send("");
  while (xmlhttp.readyState != 4) { }
  xmlDoc = xmlhttp.responseXML;
  readXML();
  
  }
  
  
  function readXML() {
  
  while (subChunk &lt; 20) {
      *indvCount = xmlDoc.getElementsByTagName("Value")[subChunk].childNodes[0].nodeValue;
      total = parseInt(total, 10) + parseInt(indvCount, 10);
      subChunk = parseInt(subChunk, 10) + parseInt(1, 10);
  }
  chunk = parseInt(chunk, 10) + parseInt(1, 10);
  subChunk = parseInt(0, 10)
  end = parseInt(chunk, 10) * parseInt(20, 10);
  start = parseInt(end, 10) - parseInt(19, 10);
  if (chunk &gt; max) {
      alert(total);
  } else {
      loadXML();
  }
  
  }
  </code></pre>
  
  <p>When <code>chunk</code> is equal to approx. 5,000 or more, I get an <code>Out of Memory</code> error. The error usually refers to one of the asterisk'ed lines of code. Using Windows Task Manger, I can confirm that Internet Explorer's memory usage stays at about 6,000K, so I don't think I have a memory leak.</p>
  
  <p>Does anyone know a way to prevent this?</p>