0

When a directive is instantiated, a watch is configured.

scope.$watch('propertyName', function(value) {});

Do I have do do anything to prevent a memory leak when the directive is destroyed?

Ben Aston
  • 53,718
  • 65
  • 205
  • 331

1 Answers1

1

No -- angular will take care of cleaning up watches when the associated scope gets destroyed.

If you want to clear a watch however; the $watch function returns a function, which will de-register the watch when called.

var unregister = $scope.$watch('myVar', function() { /* ... */ });
unregister();
null
  • 7,906
  • 3
  • 36
  • 37