关于struct间的循环引用

lyly · · 2769 次点击
关键你这样的结构,你怎么实例化 A、B、C 呢?
#1
更多评论
没问题的,A和B的实例之间相互引用是可以被回收的,只要这两个实例没有在其它地方被引用到 In a tri-color collector, every object is either white, grey, or black and we view the heap as a graph of connected objects. At the start of a GC cycle all objects are white. The GC visits all roots, which are objects directly accessible by the application such as globals and things on the stack, and colors these grey. The GC then chooses a grey object, blackens it, and then scans it for pointers to other objects. When this scan finds a pointer to a white object, it turns that object grey. This process repeats until there are no more grey objects. At this point, white objects are known to be unreachable and can be reused. https://blog.golang.org/go15gc https://groups.google.com/forum/#!topic/golang-nuts/tzvgeBEW1WY
#2