Skip to content

Commit 2472a72

Browse files
author
Simon Oxtoby
committed
Applying Zap's memory leak changes & exposing escapeForRegexp.
1 parent 46b7cf7 commit 2472a72

File tree

7 files changed

+65
-4
lines changed

7 files changed

+65
-4
lines changed

Diff for: src/AngularPublic.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ function publishExternalAPI(angular) {
148148
'getTestability': getTestability,
149149
'$$minErr': minErr,
150150
'$$csp': csp,
151-
'reloadWithDebugInfo': reloadWithDebugInfo
151+
'reloadWithDebugInfo': reloadWithDebugInfo,
152+
'escapeForRegexp': escapeForRegexp
152153
});
153154

154155
angularModule = setupModuleLoader(window);

Diff for: src/auto/injector.js

+20
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,26 @@ function createInjector(modulesToLoad, strictDi) {
843843
annotate: createInjector.$$annotate,
844844
has: function(name) {
845845
return providerCache.hasOwnProperty(name + providerSuffix) || cache.hasOwnProperty(name);
846+
},
847+
848+
// V8LeakFix
849+
dispose: function () {
850+
var disposed = [];
851+
cleanAndDispose(cache);
852+
cleanAndDispose(providerCache);
853+
disposed = undefined;
854+
855+
function cleanAndDispose(target) {
856+
for (var p in target) {
857+
if (target.hasOwnProperty(p)) {
858+
if (p != '$injector' && target[p] && target[p].dispose && isFunction(target[p].dispose) && disposed.indexOf(target[p] == -1)) {
859+
disposed.push(target[p]);
860+
target[p].dispose();
861+
}
862+
delete target[p];
863+
}
864+
}
865+
}
846866
}
847867
};
848868
}

Diff for: src/ng/cacheFactory.js

+8
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,14 @@ function $CacheFactoryProvider() {
347347
};
348348

349349

350+
// V8LeakFix
351+
cacheFactory.dispose = function () {
352+
for (var v in caches)
353+
if (caches.hasOwnProperty(v))
354+
caches[v].destroy();
355+
}
356+
357+
350358
return cacheFactory;
351359
};
352360
}

Diff for: src/ng/http.js

+8
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,14 @@ function $HttpProvider() {
11351135
$http.defaults = defaults;
11361136

11371137

1138+
// V8LeakFix
1139+
$http.dispose = function () {
1140+
for (var v in $http)
1141+
if ($http.hasOwnProperty(v))
1142+
delete $http[v];
1143+
};
1144+
1145+
11381146
return $http;
11391147

11401148

Diff for: src/ng/parse.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ function $ParseProvider() {
17111711
expensiveChecks: true
17121712
};
17131713

1714-
return function $parse(exp, interceptorFn, expensiveChecks) {
1714+
function $parse(exp, interceptorFn, expensiveChecks) {
17151715
var parsedExpression, oneTime, cacheKey;
17161716

17171717
switch (typeof exp) {
@@ -1749,8 +1749,16 @@ function $ParseProvider() {
17491749
default:
17501750
return noop;
17511751
}
1752+
}
1753+
1754+
// V8LeakFix
1755+
$parse.dispose = function () {
1756+
cacheDefault = undefined;
1757+
cacheExpensive = undefined;
17521758
};
17531759

1760+
return $parse;
1761+
17541762
function expressionInputDirtyCheck(newValue, oldValueOfValue) {
17551763

17561764
if (newValue == null || oldValueOfValue == null) { // null/undefined

Diff for: src/ng/rootScope.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -779,15 +779,16 @@ function $RootScopeProvider() {
779779
lastDirtyWatch = watch;
780780
watch.last = watch.eq ? copy(value, null) : value;
781781
watch.fn(value, ((last === initWatchVal) ? value : last), current);
782-
if (ttl < 5) {
782+
// V8LeakFix
783+
/*if (ttl < 5) {
783784
logIdx = 4 - ttl;
784785
if (!watchLog[logIdx]) watchLog[logIdx] = [];
785786
watchLog[logIdx].push({
786787
msg: isFunction(watch.exp) ? 'fn: ' + (watch.exp.name || watch.exp.toString()) : watch.exp,
787788
newVal: value,
788789
oldVal: last
789790
});
790-
}
791+
}*/
791792
} else if (watch === lastDirtyWatch) {
792793
// If the most recently dirty watcher is now clean, short circuit since the remaining watchers
793794
// have already been tested.
@@ -873,6 +874,11 @@ function $RootScopeProvider() {
873874
$destroy: function() {
874875
// We can't destroy a scope that has been already destroyed.
875876
if (this.$$destroyed) return;
877+
878+
// V8LeakFix (recursively destroy child scopes)
879+
while (this.$$childHead)
880+
this.$$childHead.$destroy();
881+
876882
var parent = this.$parent;
877883

878884
this.$broadcast('$destroy');
@@ -908,6 +914,7 @@ function $RootScopeProvider() {
908914
// - https://github.com/angular/angular.js/issues/6794#issuecomment-38648909
909915
// - https://github.com/angular/angular.js/issues/1313#issuecomment-10378451
910916

917+
this['this'] = this.$$ChildScope = // V8LeakFix
911918
this.$parent = this.$$nextSibling = this.$$prevSibling = this.$$childHead =
912919
this.$$childTail = this.$root = this.$$watchers = null;
913920
},

Diff for: src/ng/timeout.js

+9
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ function $TimeoutProvider() {
9292
return false;
9393
};
9494

95+
// V8LeakFix
96+
timeout.dispose = function () {
97+
for (var p in deferreds)
98+
if (deferreds.hasOwnProperty(p)) {
99+
deferreds[p].reject('destroyed');
100+
delete deferreds[p];
101+
}
102+
};
103+
95104
return timeout;
96105
}];
97106
}

0 commit comments

Comments
 (0)