Hacker News new | past | comments | ask | show | jobs | submit login

A quick example of where circular references are an issue in C++, but weak references aren't needed in other languages. Consider a doubly-linked list, where you remove two nodes from the middle, and those nodes are not reachable from anywhere else. Each node, however, still has a reference to the other:

    X<->Y
In any system with a full GC, those nodes will get freed; in a reference counting system, those nodes will stay around forever.



But why have you designed your interface in such a way that this could happen?

A normal interface would allow you to remove one node at a time and this wouldn't occur.

A more advanced interface may allow you to remove 2 nodes, but would return a vector or a new list to ensure proper deallocation.

Don't get me wrong; you have to think with C++ and generally know what you're doing. However, you can write safe and high level C++ and I don't necessarily think thinking about your design is a bad thing.


I'm not addressing that part; I'm merely pointing out that circular references are solvable without weak references.




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

Search: