Last active
January 3, 2016 10:59
-
-
Save ben-ng/8453114 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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