In V8 if I have a closure such as in this example where I have a
function f that returns an anonymous closure:

function f() {
    var x = 0;
    var y = 1;
    return function() {
        return x + y;
    };
}

In V8 does the returned closure keep two pointers (one to x, and one
to y), or does it keep a single pointer back to the execution context
of f? Or does it do something else altogether?

Also, can anyone give me pointers to what files in the V8 source code
I should take a look at to get an understanding of how this works?

Partially, I'm just curious, and partially I'm wondering about
performance implications. If f defined way more variables, is each
closure going to chew up more memory to keep track of all of those
pointers?

Also, from a GC perspective, I'm wondering in the case that something
like this happens:
function g() {
    var x = 0
    var y = 1;
    return function() {
        return x;
    };
}

// lets day h is a global that sticks arround forever.
var h = g();

Will y never be garbage collected since its part of an execution
context pointed to by the closure held in h?

Thanks, and again, pointers back to the source code are appreciated.

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to