title: Angular + Mocha memory leak
body: <p>I'm getting the following error when running the entire suite of tests:</p>
  <p><code>timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.</code></p>
  <p>After some investigation, I found out to be a memory leak issue. Looking at some heap profiling snapshot, objects still seem to be referenced and not getting garbaged collected.</p>
  <p>Anyone know a solution that would prevent it from happening? There's some options such as going through each one of my 1000ish specs and adding <code>afterEach</code> to do some clean up, but that seems like a lot of work.</p>
  <p>Here's a sample layout of how most of my tests look like</p>
  <pre><code>describe('MyClassCtrl', function() {
  
    var $httpBackend, $rootScope, ctrl;
    ctrl = $rootScope = $httpBackend = null;
  
    beforeEach(function() {
      module('myApp');
      inject(function($controller, $rootScope, _$httpBackend_, $stateParams) {
        var $scope;
        $stateParams.id = 1;
        $httpBackend = _$httpBackend_;
        $scope = $rootScope.$new();
        ctrl = $controller('MyClassCtrl', {
          $scope: $scope
        });
      });
    });
  
    describe('#_getMyList', function() {
      beforeEach(function() {
        $httpBackend.expectGET(&quot;/my/app/url&quot;).respond({
          my_list: [1, 2, 3]
        });
        ctrl._getMyList();
        $httpBackend.flush();
      });
  
      it('does this', function() {
        expect(ctrl.my_list).to.eql([1, 2, 3]);
      });
    });
  });
  </code></pre>
  <p>Below are some profiling screenshots:</p>
  <p><a href="https://i.stack.imgur.com/QRDXB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QRDXB.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/CcOC1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CcOC1.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/l5gCw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l5gCw.png" alt="enter image description here" /></a></p>
  <p><strong>UPDATE</strong></p>
  <p>I was able to trigger a memory leak by simply wrapping one of my <code>it</code> in a loop.</p>
  <p>e.g.:</p>
  <pre><code>for (i = 0; i &lt; 200; i++) {
    it('does this', function() {
      expect(ctrl.my_list).to.eql([1, 2, 3]);
    });
  }
  </code></pre>
  <p>In my tests, I set all objects within a container object and cleaned it up in an <code>afterEach</code> (like the solution <a href="https://stackoverflow.com/questions/32998442/angularjs-unit-testing-memory-leaks">here</a>) but no luck. Memory allocation still keep increasing on Chrome's Dev Timeline tool.</p>
  <p>Thanks!</p>