Skip to content

Instantly share code, notes, and snippets.

@domluna
Created November 13, 2013 03:32
Show Gist options
  • Save domluna/7443260 to your computer and use it in GitHub Desktop.
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.
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