Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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.

It absolutely should be GC'd. To demonstrate (on node again), this uses about 10MB of RSS, because obj.a cannot be GC'd.

  j = function() {
    var obj = {
      a:  new Array(1000000).join('*'),
      b:  5
    };
    return obj;
  }();
  setTimeout(function() {}, 30000);
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...



V8's GC is both generational and incremental.

Generational can be actually viewed as a variation of incremental GC.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: