3 ms·
If the parent is the only place where there's a reference to the child view, then yes. However like the article says, you often have things like event listener
by jpk 14y ago
If the parent is the only place where there's a reference to the child view, then yes. However like the article says, you often have things like event listeners that, if the child view doesn't clean up, will prevent the child view from getting collected. (And often, the listeners still do stuff causing buggy behavior.)
This is fixed by ensuring there's an off()/unbind() for every on()/bind(). I do this by following a pattern like the one in this article: http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/ http://lostechies.com/derickbailey/2011/09/15/zombies-run-ma...
- andrewvc 14y agoYes, but if they are bound to the child's element and that is removed shouldn't that be sufficient unless the view is binding to other elements or window events?
- sim0n 14y agoBackbone Views often bind to model/collection events.
- m64253 14y agoIt's quite common to bind to events on objects like models or collections etc. which will not be unbound just because the dom element is.
- Flow 14y agoIsn't that true only for older Internet Explorer versions because they had two garbage collectors, one for DOM stuff and one for JScript stuff?
- chrizel 14y agoThat's not a problem just for IE. It's a problem that browser vendors could only solve by giving us WeakMaps (which could come in ES6 http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps#weakmap http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps#wea... )... The problem is, you have a bunch of subviews which are registering events on some collection models... when you rerender your parent view your subviews get recreated but your previously created subviews stay in memory because the backbone events system still stores references to the old views which aren't really needed anymore. The only solution is to explicitly remove the events when subviews a destroyed (or better use a solution like in the submitted article) or use a library like https://github.com/marionettejs/backbone.eventbinder https://github.com/marionettejs/backbone.eventbinder