Reputation: 2530
I am analyzing the code of my application AngularJs to try Maximising performance and i put this code in my controller
$scope.$on("$destroy", () ->
console.log "DESTROY SCOPE OF CONTROLLER BEFORE EXIT"
console.log window.performance.memory
$scope.$destroy()
console.log window.performance.memory
)
So
$scope.$destroy()
should clear the scope of my controller and its children. The problem is that when I leave the controller and activates the event $ destroy, in console I see that the logs are in the loop. Why?
Thank you all
Upvotes: 1
Views: 4926
Reputation: 4874
You can find a part of the answer in the documentation concerning scope life cycle.
In your case you're calling the $destroy event in the listener. So you're doing a recursive call of the $destroy event.
Upvotes: 1