Posts

Showing posts from May, 2015

Angular 1.x memory leaks and cleanup

Angular cleans up and unbinds listeners and watches on scope and also unbinds directive elements (so you don't need to worry about those e.g. calling element.off() in a directive destroy). "Listeners registered to scopes and elements are automatically cleaned up when they are destroyed,"  - ok so you don't need to unbind listeners from scope or element But long running timeouts/intervals should be cleaned up on destroy. Short running timeouts can be assumed to be safe (completed before user leaves that code). "Any listeners that we manually add or intervals or timeouts that are currently executing need to be cleaned up in $destroy event" Whats a long running interval/timeout? I'd say 500ms and over should be explicitly released. Directives can be a source of leaks. Any listeners to service layers or to other DOM elements must be explicitly unbound on directive destroy (directive scope gets destroy event, so does the element). "...but if yo