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

SCOPE DESTRUCTION: Leak when asynchronously continuing the linking of directives on scopes that are already destroyed #9199

Closed
lgalfaso opened this issue Sep 21, 2014 · 4 comments
Assignees
Milestone

Comments

@lgalfaso
Copy link
Contributor

When a directive uses a templateUrl, this directive is inside an ng-switch or an ng-if and the following events happen in this specific order

  • The html of the ng-switch starts it's compilation
  • The directive inside the ng-switch starts it's compilation, the template is requested from the server
  • The synchronous part of the compilation ends
  • The condition on the ng-switch changes so the directive should be displayed
  • ng-switch transcludes the content of the ng-switch-when (only what it can as the template did not finish loading)
  • The expression at ng-switch changes so the directive should not be displayed
  • ng-switch destroys the scope
  • The template finishes loading, the scope (even when it is already destroyed) is added to the element.data (here is where we have the leak)

Here is a plunker that shows this
http://plnkr.co/edit/tNMYYHgoebX1Vx0hWZAb?p=preview

Note: This issue is based on a modification of #9197

@lgalfaso lgalfaso changed the title Leak when asynchronously continuing the compilation of nodes Leak when asynchronously continuing the linking of directives on scopes that are already destroyed Sep 21, 2014
@caitp
Copy link
Contributor

caitp commented Sep 21, 2014

did we really need to create a new issue for this? it's basically the same thing as the one you were commenting on is it not?

@lgalfaso
Copy link
Contributor Author

@caitp I created the new issue to be sure it is tracked as a leak and not as something that can cause no harm. That said, I am ok with just moving everything to the original issue

lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Sep 22, 2014
Stop an asynchronous compilation when this is performed on an
already destroyed scope

Closes angular#9199
@lgalfaso
Copy link
Contributor Author

Posted an update on #9079 that solves this issue

@petebacondarwin
Copy link
Contributor

I commented on the two commits in #9079. I believe the commit that prevents double destroy events could cause memory leaks and proposed a different solution of actually recursing down the scope hierarchy and calling $destroy on all descendants, based on the fact that #9281 would make the scope hierarchy more conducive to this - currently this would fail to destroy transcluded scopes.
I think the second commit is the right thing to do assuming that we really have destroyed the descendant scopes.

@petebacondarwin petebacondarwin changed the title Leak when asynchronously continuing the linking of directives on scopes that are already destroyed SCOPE DESTRUCTION: Leak when asynchronously continuing the linking of directives on scopes that are already destroyed Sep 26, 2014
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Sep 28, 2014
Stop an asynchronous compilation when this is performed on an
already destroyed scope

Closes angular#9199
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Sep 29, 2014
Stop an asynchronous compilation when this is performed on an
already destroyed scope

Closes angular#9199
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Sep 29, 2014
Stop an asynchronous compilation when this is performed on an
already destroyed scope

Closes angular#9199
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Sep 29, 2014
Stop an asynchronous compilation when this is performed on an
already destroyed scope

Closes angular#9199
Closes angular#9079
Closes angular#8504
Closes angular#9197
petebacondarwin added a commit that referenced this issue Sep 29, 2014
Stop an asynchronous compilation when this is performed on an
already destroyed scope

Closes #9199
Closes #9079
Closes #8504
Closes #9197
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants