I guess this would solve the problem but it would also be slow because traversing the list via weak_ptr requires a conversion from weak_ptr to shared_ptr for every item.
There isn't any choice in RC systems in presence of cycles, either weak pointers or a presence of cycle collector.
Anything else is unsafe, specially if the pointer is allowed to escape the RC object that contains it.
And this is one of the reasons why usually optimized GCs outperform RC solutions.
Unless approaches like affine types or counting elision are used, but those fail down in the presence of cycles, forcing the developers to use other approaches to represent cycles.
Anything else is unsafe, specially if the pointer is allowed to escape the RC object that contains it.
And this is one of the reasons why usually optimized GCs outperform RC solutions.
Unless approaches like affine types or counting elision are used, but those fail down in the presence of cycles, forcing the developers to use other approaches to represent cycles.