Does Chrome's javascript garbage collection work differently?

garbage-collection, google-chrome, javascript, v8

Solution

This doesn't have anything to do with garbage collection or the debug tools.

What's actually happening is that Chrome's JS engine realizes that you never use `numb` inside the function, so it doesn't include it in the closure at all.

Note that it can only do this if it can prove that the inner function never uses `with` or calls `eval`.

Problem

When I try to debug this code (http://jsfiddle.net/QWFGN/) ``` var foo = (function(numb) { return { bar: function() { debugger; return "something"; } } })(1); foo.bar() ``` Developer tool in Chrome behaves differently than and Firebug in Firefox and developer tool in IE. The issue is that variable `numb` is not visible in Chrome developer tool on the `debugger;` line. But, it is visible in Firebug and IE. If I try to type `numb` in Chrome's console I get: ``` ReferenceError: numb is not defined ``` `numb`, of course, is visible in this closure, and if I change code to (http://jsfiddle.net/QWFGN/1/) ``` var foo = (function(numb) { return { bar: function() { debugger; console.log(numb); return "something"; } } })(1); foo.bar() ``` `numb` is now visible in Chrome as well and I can get value `1` as a response. So, My question is: Why only Google Chrome doesn't see closure variables that are never used? Does Google Chrome have it's own implementation of Garbage Collection, or is it only related to implementation of debug tool in Google Chrome.

Original source

Related problems