Created
March 8, 2015 19:06
-
-
Save DrewMartin/2ec774e088fdb26a425b to your computer and use it in GitHub Desktop.
jQuery memory leaking
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
| (function() { | |
| var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | |
| window.Leak = (function() { | |
| function Leak(node, data) { | |
| this.data = data; | |
| this.onNodeChanged = __bind(this.onNodeChanged, this); | |
| $(node).on("change", this.onNodeChanged); | |
| } | |
| Leak.prototype.onNodeChanged = function() { | |
| return console.log("node changed with data", this.data); | |
| }; | |
| return Leak; | |
| })(); | |
| }).call(this); | |
| node = $('<div id="will-leak"></div>')[0]; | |
| document.body.appendChild(node); | |
| new Leak(node, 'gibberish'); | |
| $(node).trigger('change'); | |
| node2 = $('<span id="replace-leak"></span>')[0]; | |
| document.body.replaceChild(node2, node); | |
| // $(node).remove() | |
| node = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment