I'm trying to prevent a memory leak caused by part of the code which doesn't get fired when the element is destroyed.
My code attaches an event to the document
on mouseup
and does stuff with a particular element of the DOM. If the element is removed, the event should be disabled by willDestroyElement
of Ember but some times it doesn't happens so I need to disable it manually.
To do so I put on the very begin of my event function this string:
onMouseUp: function(evt) {
// relevant part of the code:
if (!this.$()) {
return $(document).off(evt);
}
[...]
In this way looks like the event is correctly unbinded from the document
.
I can't find documentation about this use case and I'd like to know if doing so could lead to side effects or anything bad?
Aucun commentaire:
Enregistrer un commentaire