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

It's easily decidable whether a given GC object could be reached. What isn't decidable is whether a it will be used in the future.

The conservative approximation that GC's make is that they keep all objects that could be accessed in the future by the program (reach-able) instead of only keeping the objects that will be used in the future.

A trivial example is:

    void main() {
      var obj = new Object();

      while (true) {
        // Do other work...

        if (dayOfWeek == 9) {
          print(obj);
        }
      }
    }
Since there are only seven days in the week, that `print()` statement will never be reached, and an optimal GC would free obj. But the GC can't determine that. All it knows is that it could possibly be reached, so the object stays in memory.





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

Search: