Yes weakrefs() are one thing that causes DDS a lot of problems, they completely screw DDS and there really is nothing I can do about it.
As for the advice that weakrefs are the correct way to do self referential structures, I disagree. There really is no reason to require weakrefs and in fact IMO when you design self referential structures without using weakrefs you get certain benefits that are available when you do not use weakrefs.
The central idea is that you use a stub object that isnt part of the self referential structure as the root or container of the structure. Since the root is not part of the reference cycle its refcount will decrement properly when it falls out of use, which will then trigger the DESTROY{} method which will then traverse the structure and eliminate the reference cycles. This is a useful design anyway as you can now use the root for various bookeeping efforts like how many nodes their are, different entry points into traversing the structure, even state information for things like iterators. All of these latter things are impossible or very difficult to accomplish with a "no container class using weakrefs" type data structure.
|