Created
November 13, 2013 03:32
-
-
Save domluna/7443260 to your computer and use it in GitHub Desktop.
Example of unreachable function in JS closure, good to keep in mind for when writing JS code
Note browsers need functions in closures to be "explicitly unreachable" in order for garbage collection.
This file contains 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 someFunc = function() {}; | |
function f() { | |
var some = new someFunc(); // this won't be garbage collected!!! | |
function unreachable() {}; | |
return function() {}; | |
} | |
window.f_ = f(): | |
// some references a new someFunc() but there's no way to access some now! It's still there it's just not doing anything. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment