Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

perf(rootScope): Fix a memory leak #11173

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,27 @@ function $RootScopeProvider() {
return TTL;
};

function createChildScopeClass(parent) {
function ChildScope() {
this.$$watchers = this.$$nextSibling =
this.$$childHead = this.$$childTail = null;
this.$$listeners = {};
this.$$listenerCount = {};
this.$$watchersCount = 0;
this.$id = nextUid();
this.$$ChildScope = null;
}
ChildScope.prototype = parent;
return ChildScope;
}

this.$get = ['$injector', '$exceptionHandler', '$parse', '$browser',
function($injector, $exceptionHandler, $parse, $browser) {

function destroyChildScope($event) {
$event.currentScope.$$destroyed = true;
}

/**
* @ngdoc type
* @name $rootScope.Scope
Expand Down Expand Up @@ -206,16 +224,7 @@ function $RootScopeProvider() {
// Only create a child scope class if somebody asks for one,
// but cache it to allow the VM to optimize lookups.
if (!this.$$ChildScope) {
this.$$ChildScope = function ChildScope() {
this.$$watchers = this.$$nextSibling =
this.$$childHead = this.$$childTail = null;
this.$$listeners = {};
this.$$listenerCount = {};
this.$$watchersCount = 0;
this.$id = nextUid();
this.$$ChildScope = null;
};
this.$$ChildScope.prototype = this;
this.$$ChildScope = createChildScopeClass(this);
}
child = new this.$$ChildScope();
}
Expand All @@ -233,13 +242,9 @@ function $RootScopeProvider() {
// prototypically. In all other cases, this property needs to be set
// when the parent scope is destroyed.
// The listener needs to be added after the parent is set
if (isolate || parent != this) child.$on('$destroy', destroyChild);
if (isolate || parent != this) child.$on('$destroy', destroyChildScope);

return child;

function destroyChild() {
child.$$destroyed = true;
}
},

/**
Expand Down