Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 1ba5bef

Browse files
committed
fix(changed-detection): leaking watch records when removing deeply nested watch_groups
Closes #700
1 parent 5a36808 commit 1ba5bef

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/change_detection/watch_group.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
291291

292292
// Unlink the _watchRecord
293293
_EvalWatchRecord firstEvalWatch = _evalWatchHead;
294-
_EvalWatchRecord lastEvalWatch =
295-
(_watchGroupTail == null ? this : _watchGroupTail)._evalWatchTail;
294+
_EvalWatchRecord lastEvalWatch = _childWatchGroupTail._evalWatchTail;
296295
_EvalWatchRecord previous = firstEvalWatch._prevEvalWatch;
297296
_EvalWatchRecord next = lastEvalWatch._nextEvalWatch;
298297
if (previous != null) previous._nextEvalWatch = next;

test/change_detection/watch_group_spec.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ void main() {
602602
var child1a = watchGrp.newGroup(new PrototypeMap(context));
603603
var child1b = watchGrp.newGroup(new PrototypeMap(context));
604604
var child2 = child1a.newGroup(new PrototypeMap(context));
605+
var child3 = child2.newGroup(new PrototypeMap(context));
605606
child1a.watch(countMethod, (v, p) => logger('1a'));
606607
expectOrder(['0a', '1a']);
607608
child1b.watch(countMethod, (v, p) => logger('1b'));
@@ -612,12 +613,14 @@ void main() {
612613
expectOrder(['0a', '0A', '1a', '1A', '1b']);
613614
child2.watch(countMethod, (v, p) => logger('2A'));
614615
expectOrder(['0a', '0A', '1a', '1A', '2A', '1b']);
616+
child3.watch(countMethod, (v, p) => logger('3'));
617+
expectOrder(['0a', '0A', '1a', '1A', '2A', '3', '1b']);
615618

616619
// flush initial reaction functions
617-
expect(watchGrp.detectChanges()).toEqual(6);
618-
expectOrder(['0a', '0A', '1a', '1A', '2A', '1b']);
620+
expect(watchGrp.detectChanges()).toEqual(7);
621+
expectOrder(['0a', '0A', '1a', '1A', '2A', '3', '1b']);
619622

620-
child1a.remove(); // should also remove child2
623+
child1a.remove(); // should also remove child2 and child 3
621624
expect(watchGrp.detectChanges()).toEqual(3);
622625
expectOrder(['0a', '0A', '1b']);
623626
});

0 commit comments

Comments
 (0)