fix(async pipe): prevent firing $digest after scope is destroyed. #220
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
async pipe could trigger digest after scope was destroyed.
It could result in memory leak, because digest will trigger async pipe (like a filter), making it to subscribe observable in already destroyed scope (and
$destroy
won't happen again).The source of the problem for async pipe is
_markForCheck
method, that sets timeout, and triggers$digest
without checking if scope is destroyed.Solution: track timeouts and clean them while
_dispose
and before setting new timeout.For test, set of
async-destroy
components were created. Clicking 'start' button dispatches change inSubject
imitating application state. If 'Memory leak' (when digest called after scope being destroyed) happened, alert message will be shown. To test fail scenario commentclearTimeout
lines ifasync
pipe.The key point is "middle"
async-destroy-container
component that on$destroy
triggers synchronous change ofSubject
. Thats a scenario when component on destroy want to change the state of application.