Removing events when detaching/destroying view?


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?


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.


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.