Created
June 5, 2012 00:45
-
-
Save toddpi314/2871733 to your computer and use it in GitHub Desktop.
Closure Pinning Memory Leak
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
// Component Definition | |
function Component(name) { | |
this.pageName = name; | |
} | |
// Lets decorate the Component instances with | |
// a method that can do some work | |
Component.prototype.onLoaded = function() { | |
// do some fancy work | |
} | |
// On Component.attach, lets subscribe to the | |
// DOM's loaded event and do something on our | |
// self closure context | |
Component.prototype.attach = function() { | |
var self = this; | |
$(document).load(function() { | |
self.onLoaded(); | |
}); | |
} | |
// Test Case: Create a ton of Components | |
for (var i = 0; i <= 4; i++) { | |
var newComponent = new Component('my page'); | |
newComponent.attach(); | |
delete newComponent; | |
newComponent = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment