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

Garbage collectors have no problem with reference cycles.

A GC works by finding all objects that are reachable (referenced by some other object or a root), then discarding all other objects. So a cyclic data structure is completely discarded as soon as there are no live references to any of its objects.

As usual, Wikipedia has lots more information: http://en.wikipedia.org/wiki/Garbage_collection_(computer_sc...

GC roots are generally things like: static/global variables, active stack frames (function parameters and local variable), CPU registers.



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

Search: