title: Phantomjs dies by high memory consumption
body: <p>We are using phantomjs to run our qunit tests page on our TFS build server. Our version of test runner is built from below example </p>
  
  <p><a href="https://github.com/ariya/phantomjs/blob/master/examples/run-qunit.js">https://github.com/ariya/phantomjs/blob/master/examples/run-qunit.js</a></p>
  
  <p>Over a period of time number of tests increased from hundreds to couple of thousands and on a fine day phantomjs started crashing. It literally dies saying upload the dump and when you see the dump it 0kb !!</p>
  
  <p>When we took a closer look at it on process explorer we found that memory consumption by phantomjs keeps going up as phantomjs is running tests and eventually crashes somewhere 833MB. </p>
  
  <p>Yes the same amount of memory was being utilized by chrome and IE ! And Yes-Yes our tests were leaking memory :(. We did fixed it, memory utilization is lowered by 50% on chrome and IE and we expected phantomjs will handle it now. But no, phantomjs still kept crashing, process explorer shows same memory consumption. </p>
  
  <p><a href="http://phantomjs.org/api/webpage/method/close.html">http://phantomjs.org/api/webpage/method/close.html</a></p>
  
  <p>According to above documentation phantomjs releases heap allocation just on close ? Could that be the reason why our fixed test consumed less memory on chrome but not phantomjs ? And last how to fix this  ? How to make phantomjs keep garbage collecting javascript objects to reduce heap allocation ?</p>
  
  <p><strong>Update 1 - 07/28</strong></p>
  
  <p>We took a work around. I did modified my script to execute my tests module by module. In loop after executing all tests for a module I call page.close so it releases the memory for each module and never keeps building the dead heap of objects. Not closing this question since since its a workaround and not a solution. Hope creators will fix this sometime.</p>