Skip to content

Instantly share code, notes, and snippets.

@ben-ng
Last active January 3, 2016 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben-ng/8453114 to your computer and use it in GitHub Desktop.
Save ben-ng/8453114 to your computer and use it in GitHub Desktop.
var MyView = Ribcage.View.extend({
afterInit: function (opts) {
this.action = opts.action;
}
, beforeRender: function () {
this.button = new ButtonView({
action: this.action
});
}
, afterRender: function () {
this.appendSubView(this.button, this.$('.here'));
}
, beforeClose: function () {
delete this.button;
}
, template: function () {
return '<div class="here"></div>'
}
});
var aView = new MyView({action: function () {
console.log('I was made in a parent closure');
}});
document.body.appendChild(aView.el);
aView.render();
aView.render();
aView = null;
// You have now leaked aView and all its DOM nodes
// because two buttons were leaked in the three calls to render
// (one hidden call to render in the initializer)
// jQuery is still hanging on to the two buttons in its cache
// wat.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment