I've seen a lot of directive examples including those by the AngularUI team where they don't appear to do any cleanup.
Here's an example from their ui-date directive which creates a jQuery datepicker. (source)
element.on('blur', function() { ... });
They placed an event handler on the element, but at no point do they ever unbind the event. I would have expected there to be code present such as:
var namespace = ".uiDate";
element.on('blur' + namespace, function() { ... });
element.on("$destroy" + namespace, function ()
{
element.datepicker("destroy"); //Destroy datepicker widget
element.off(namespace); //Unbind events from this namespace
});
So this makes me wonder if there's something I don't understand. Wouldn't what they are doing cause a memory leak in situations where the element w/ this directive is created and destroyed over and over?
What am I missing?