AngularJs $scope.$destroy(). How to use?

4.8k Views Asked by At

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?

enter image description here

Thank you all

1

There are 1 best solutions below

0
On

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.