Removing events when detaching/destroying view?


#1

Do I have to remove view events when detaching views? Wouldn’t the views get garbage-collected taking the DOM elements and events with it?


#2

As you are never sure when the GC will pass I took the habit to always remove events whatever the context, but I’m not sure it makes a real difference here. And I’m not knowledgeable enough regarding jQuery internal to say if there’s potential leaks by not doing so. What’s sure is that if you get a subscription when registering to that event, the subscription itself may be a potential leak as it hold a reference to its origin.


#3

If you have events still registered, they will not be garbage collected because the emitter still holds a reference. Chances are your views will not be collected either because the event handlers will hold a reference to them. The emitter will continue to call anything you’ve left registered.