BossView
BossView copied to clipboard
Call destroy on parent doesn't destroy the subviews.
Problem :
Calling destroy on BossView object doesn't call destroy on subviews, resulting on a potential memory leak.
Subviews' "onDestroy" never get called, and in the Chrome Backbone Debugger we can see that the subviews get destroyed, in a way (?!)(but this debugger is not always accurate), but all their own children are kept alive.
Solution :
I've added destroy as the remove call
destroy: function () {
Marionette.ItemView.prototype.destroy.apply(this, arguments);
this._destroySubViews();
},
_destroySubViews: function () {
_.each(this.initializedSubViews, function(subView) {
subView.destroy();
});
}
It does the trick for me but I don't have the time to make the unit test and a pull request. Add if you think it's relevant.
Also found this problem when was hunting down huge memory leaks. Here's my simplier fix:
onDestroy: function onDestroy() {
_.invoke(this.initializedSubViews, 'destroy');
}