title: AngularJS Karma Unit-Tests Memory Leak
body: <p>we are currently working on an angularjs project with round about 2500 Jasmine test cases. We are using chrome as browser and the karma-ng-html2js-preprocessor to preprocess our templates. </p>
  
  <p>We are now facing the problem that our tests consuming a huge amount of memory and our karma server disconnects, because latter tests are taking way too long. Approximately 2000 tests are executed in 3 mins, but the last 500 are taking up to 10 mins. We tried several solutions we found online to get rid of this problem, but nothing is working. We tried the following solutions:</p>
  
  <ul>
  <li>use this-operator: <a href="https://gist.github.com/traviskaufman/11131303" rel="nofollow noreferrer">https://gist.github.com/traviskaufman/11131303</a></li>
  <li>declare variables in afterEach: <a href="https://blog.thecodecampus.de/avoid-memory-leaks-angularjs-unit-tests/" rel="nofollow noreferrer">https://blog.thecodecampus.de/avoid-memory-leaks-angularjs-unit-tests/</a></li>
  </ul>
  
  <p>We analysed the memory usage with the chrome memory snapshot tool. The first snapshot was taken after 300 Tests and the second after 600 Tests. </p>
  
  <p><a href="https://i.stack.imgur.com/v0vgP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v0vgP.png" alt="First Snapshot (300 Tests)"></a>
  <a href="https://i.stack.imgur.com/XgIWu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XgIWu.png" alt="Second Snapshot (600 Tests)"></a></p>
  
  <p>Can anybody help with this problem? We are unfortunately not allowed to show some code. But our tests not differ from angular jasmine examples you can find on the web.</p>