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

Commit 847af41

Browse files
committed
fix(change-detection): remove memory leak
When the change detection finds change it creates a linked list of records which have changed. The linked list is not bound to groups but rather crosses groups, this implies that if we remove a group it is possible that a record in a live group retains a pointer to a record in the now deleted record. While technically not a leak, the memory will not be realized until that record detects another change and gets re-added to the dirty list. If the record never fires than the memory is retained forever.
1 parent a0df40a commit 847af41

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/change_detection/watch_group.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,9 @@ class RootWatchGroup extends WatchGroup {
415415
} catch (e, s) {
416416
if (exceptionHandler == null) rethrow; else exceptionHandler(e, s);
417417
}
418-
dirtyWatch = dirtyWatch._nextDirtyWatch;
418+
var nextDirtyWatch = dirtyWatch._nextDirtyWatch;
419+
dirtyWatch._nextDirtyWatch = null;
420+
dirtyWatch = nextDirtyWatch;
419421
}
420422
_dirtyWatchHead = _dirtyWatchTail = null;
421423
if (processStopwatch != null) processStopwatch..stop()..increment(count);

lib/core/scope.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ class RootScope extends Scope {
453453
}
454454
_runAsyncHead = _runAsyncHead._next;
455455
}
456+
_runAsyncTail = null;
456457

457458
digestTTL--;
458459
count = rootWatchGroup.detectChanges(
@@ -498,6 +499,7 @@ class RootScope extends Scope {
498499
}
499500
_domWriteHead = _domWriteHead._next;
500501
}
502+
_domWriteTail = null;
501503
if (runObservers) {
502504
runObservers = false;
503505
observeGroup.detectChanges(exceptionHandler:_exceptionHandler);
@@ -510,6 +512,7 @@ class RootScope extends Scope {
510512
}
511513
_domReadHead = _domReadHead._next;
512514
}
515+
_domReadTail = null;
513516
} while (_domWriteHead != null || _domReadHead != null);
514517
assert((() {
515518
var watchLog = [];

0 commit comments

Comments
 (0)