|
|
|
|
|
by oddthink
4739 days ago
|
|
I suppose I don't find it surprising, because I've used a lot of R, and R can't even optimize the simple case. There, it's for good reason, since you can extract the environment of any function, so once a closure escapes, you have a handle onto its entire containing frame. I think I've used scheme implementations that have the same "feature", with less of an excuse. It's a similar "failure of GC" if you create an object with two fields, like "obj={a: giant_value, b: 5}" then had your closure return obj.b. I bet the "a" slot would not be GC'd, even though there's no way to reach it. If your mental model is that you're holding onto the lexical frame, it's a pretty much the same behavior. |
|
It absolutely should be GC'd. To demonstrate (on node again), this uses about 10MB of RSS, because obj.a cannot be GC'd.
If you change "return obj" to "return obj.b", RSS is about 9kb.Edit: I think your understanding of GC might be coming from R's generational GC, which is a heuristic and quite different from V8's incremental GC: http://blog.chromium.org/2011/11/game-changer-for-interactiv...