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

refactor($scope): prevent multiple calls to listener on $destroy #9079

Closed
wants to merge 2 commits into from

Conversation

lgalfaso
Copy link
Contributor

Prevent isolated scopes from having listeners that get called multiple times when on $destroy

@lgalfaso lgalfaso changed the title refactor($scope): present multiple calls to listener on $destroy refactor($scope): prevent multiple calls to listener on $destroy Sep 15, 2014
@btford
Copy link
Contributor

btford commented Sep 18, 2014

I don't think this should be documented as a refactor. I think this should be a fix, since the behavior before is kind of unexpected.

@lgalfaso
Copy link
Contributor Author

@btford the reason this is marked as a refactor is #8504 (comment)

@btford
Copy link
Contributor

btford commented Sep 18, 2014

ah, okay. makes sense.

@caitp
Copy link
Contributor

caitp commented Sep 24, 2014

@lgalfaso if I understand your comment from #9199, this should fix the ngSwitch issue too yeah?

If that's the case, could we have a test which shows that the fix is working? (Yes I know there is a more general test case --- I just think it would be good to show how it's applicable to the raised issue)

@lgalfaso
Copy link
Contributor Author

@caitp this PR has two commits 47f6d46 e21c2f5

The second one has a test that is exactly as the issue posted. The reason why these are in just one PR is that the second commit needs the first to work properly

petebacondarwin referenced this pull request in lgalfaso/angular.js Sep 26, 2014
Stop an asynchronous compilation when this is performed on an
already destroyed scope

Closes angular#9199
Prevent isolated scopes from having listeners that get called
multiple times when on `$destroy`
@lgalfaso
Copy link
Contributor Author

@petebacondarwin updated the patch

@petebacondarwin
Copy link
Member

OK. I have one more thing to say here :-) (Sorry this is dragging out.)

It turns out that now that #9281 has landed, the second commit is enough on its own to ensure that the memory leak is resolved. The refactoring is not needed.

How about we land the mem leak fix and then continue the discussion about the refactoring separately?

If we accepted that double destroy is something that apps should be able to cope with then we would save more processing and memory by not wiring up all these destroy handlers on every scope.

@lgalfaso
Copy link
Contributor Author

I think that the fix for the leak, as it is in this patch, would not fix the leak without the first patch. The patch for the leak checks if the scope it was asked to continue the compilation is marked with $destroyed, and if that is the case then stop. If in the scope hierarchy between the scope that was actually destroyed and the scope that is used to link the there is an isolated scope, then the scope that is being asked to continue with the linking would not have the $destroyed property (as the isolated scope would prevent this). The first patch adds this behavior.

I am ok with still having the double destroy, but the second patch (without the first patch) would need to go up the hierarchy to know if the received scope is in a branch that was actually destroyed or not

@petebacondarwin
Copy link
Member

If you only add the "fix" commit and not the "refactor" commit to master the tests pass. Moreover the tests still pass even if you remove https://github.com/angular/angular.js/pull/9079/files#diff-a732922b631efed1b9f33a24082ae0dbR2042/.
So either the test is not strong enough or the single check for $destroyed is enough to fix the leak.

@lgalfaso
Copy link
Contributor Author

you are right, the test is not strong enough. Let me update it with a stronger test

@lgalfaso
Copy link
Contributor Author

Updated the test with a stronger version that shows the leak when the double destroy patch was not present. If it looks good, then I will split this into two clean commits

Stop an asynchronous compilation when this is performed on an
already destroyed scope

Closes angular#9199
@lgalfaso
Copy link
Contributor Author

Updated the PR by having this in only two commits and added some comments to make it clear what is going on

@lgalfaso lgalfaso closed this in 6303c3d Sep 29, 2014
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this pull request 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 pull request Sep 29, 2014
Stop an asynchronous compilation when this is performed on an
already destroyed scope

Closes #9199
Closes #9079
Closes #8504
Closes #9197
@tiff
Copy link

tiff commented Oct 5, 2014

The Changelog says that this fix also made it into v1.2.26. So I just downloaded it from angularjs.org and didn't find this change in it...

Edit: Probably because of this commit

@petebacondarwin
Copy link
Member

Ah yes, it was reverted so it should not have made it into the CHANGELOG. Sorry

bullgare pushed a commit to bullgare/angular.js that referenced this pull request Oct 9, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants