Scope Destruction - When child scopes are no longer needed , it is the
responsibility of the child scope creator to destroy them via
scope.$destroy()API. This is done in order to stop propagation of
$digest calls into the child scope and allow for memory used by the
child scope models to be reclaimed by the garbage collector.
Listeners registered to scopes and elements are automatically cleaned up when they are destroyed, but if you registered a listener on a service, rootScope or registered a listener on a DOM node that isn't being deleted, you'll have to clean it up yourself or you risk introducing a memory leak.
When $scope.$destroy()
is executed it will remove all listeners registered via $on
on that $scope
. It will not remove DOM elements or any attached event handlers added through :
element.on('click', function (event) {
...
});
More information about the angular.element https://docs.angularjs.org/api/ng/function/angular.element