Permalink
Browse files

fix(mocks): free up memory after every spec

  • Loading branch information...
1 parent 8114d55 commit 1a8642aac2de40dccdab464e58dc164006c300bb @vojtajina vojtajina committed with vojtajina Aug 30, 2012
Showing with 25 additions and 3 deletions.
  1. +25 −3 src/ngMock/angular-mocks.js
@@ -1591,9 +1591,29 @@ window.jasmine && (function(window) {
afterEach(function() {
var spec = getCurrentSpec();
+ var injector = spec.$injector;
+
spec.$injector = null;
spec.$modules = null;
+
+ if (injector) {
+ injector.get('$rootElement').unbind();
+ injector.get('$browser').pollFns.length = 0;
+ }
+
angular.mock.clearDataCache();
+
+ // clean up jquery's fragment cache
+ angular.forEach(angular.element.fragments, function(val, key) {
+ delete angular.element.fragments[key];
+ });
+
+ MockXhr.$$lastInstance = null;
+
+ angular.forEach(angular.callbacks, function(val, key) {
+ delete angular.callbacks[key];
+ });
+ angular.callbacks.counter = 0;
});
function getCurrentSpec() {
@@ -1694,7 +1714,7 @@ window.jasmine && (function(window) {
*/
window.inject = angular.mock.inject = function() {
var blockFns = Array.prototype.slice.call(arguments, 0);
- var stack = new Error('Declaration Location').stack;
+ var errorForStack = new Error('Declaration Location');
return isSpecRunning() ? workFn() : workFn;
/////////////////////
function workFn() {
@@ -1710,10 +1730,12 @@ window.jasmine && (function(window) {
try {
injector.invoke(blockFns[i] || angular.noop, this);
} catch (e) {
- if(e.stack) e.stack += '\n' + stack;
+ if(e.stack) e.stack += '\n' + errorForStack.stack;
throw e;
+ } finally {
+ errorForStack = null;
}
}
}
- }
+ };
})(window);

0 comments on commit 1a8642a

Please sign in to comment.