In short, garbage collection is the background process of the Javascript interpreter / virtual machine that automatically frees up memory for objects that your program no longer needs.
For example, since you are thinking about this for event listeners: when you delete an event listener (usually a function) from an event dispatcher, it is likely that no other part of the program will have links to the event listener. Therefore, the garbage collector can and will (at some unknown time) free up memory that was made by the event listener.
Since the closure refers to the object of the scope, in order to garbage collect the closure, it must be not only canceled, but also the area.
If you change your example a bit:
function add10(a) { var adder = function (x) { return function(y) { return x + y; } } var sum = adder(10);
After calling add10 , although the program continues to do a few more things, the garbage collector can free the memory associated with closing sum because it no longer refers, and this is the area associated with it.
In this example:
/* some stuff ... */ function add10AndGet20Adder(a) { var adders = function (x, y) { return [function(z) { return x + z; }, function(z) { return y + z; }] } var sums = adders(10, 20); //creates a closure return [sums[0](a), sums[1]]; } var result = add10AndGet20Adder(50); var sixty = result[0]; var add20 = result[1]; /* Some more stuff ... */
When performing some additional actions, sums[0] no longer referenced, BUT add20 ( sums[1] ) still has a reference to the region that refers to x and y , so neither of the two closures in sums can be freed by the garbage collector, until add20 is indicated by the program.
I hope this becomes clearer, although the examples, of course, are nowhere close to the real code. In practice, you only need to worry about this if you are developing a long-term program (for example, a single-page application or nodeJS server) with complex use of closures. Otherwise, using memory in closure is unlikely to be a problem.
This SO question gives more details on Javascript garbage collection: What is JavaScript garbage collection?