M
micah
A coworker and I stumbled across an interesting question, and I can't
find an answer to it anywhere. Specifically: Does assigning an
instance of an object to a token make it easier or harder to garbage
collect, or does it have no effect? I.e., the following lines in a
closure:
var foo = new Bar();
vs.
new Bar();
If you don't need to reference that instance of Bar again, does it
make any difference to the GC whether you assign it or not, in terms
of counting references? Does it automatically get a zero count next
time the GC runs?
Also, does that instance of Bar get locally scoped without the var
keyword, or does it end up as an orphan floating around in the global
scope? Not that that really matters, since it'd be pretty hard to have
a collision without a token... it's more just a point of curiosity.
So, any ideas?
find an answer to it anywhere. Specifically: Does assigning an
instance of an object to a token make it easier or harder to garbage
collect, or does it have no effect? I.e., the following lines in a
closure:
var foo = new Bar();
vs.
new Bar();
If you don't need to reference that instance of Bar again, does it
make any difference to the GC whether you assign it or not, in terms
of counting references? Does it automatically get a zero count next
time the GC runs?
Also, does that instance of Bar get locally scoped without the var
keyword, or does it end up as an orphan floating around in the global
scope? Not that that really matters, since it'd be pretty hard to have
a collision without a token... it's more just a point of curiosity.
So, any ideas?