Ben Morrow said:
It's not at all rare: for instance, XML::Twig has circular refs, and a
->dispose method to break them.
I'm writing about using Perl for real-world problems, specifically,
the real-world problems I used it for during the last 15 years or so,
and there, circular references where a rare occurence. For obvious
reasons, I can't comment on what people designed which
self-referential datastructures for what reasons when implenting 1
bazillion of 'generally useful' (aka 'generally useless') code
libraries available for download from server a.b.c.d.
When implementing large systems, Perl's refcounting causes problems in
practice.
Problems which occur in 'large systems' are more often than not
problems occuring because of 'the large system' which should usually
rather be structured into independent components interacting with each
other. Also, the interesting question is 'what precisely is a large
system'? Eg, it is a safe assumption that a monolithic OS kernel is
necessarily a larger 'integrated system' than most sensibly designed
applications. Yet, reference counting is (and - AFAIK - has always
been) the memory management strategy of choice for kernels (BTW, the
'large system' is another classic ivory-tower fad -- if people think
they need to implement 'large systems' then they have to find a way to
solve the problems related to that. And that they *believe* to need
something in order to solve some problem they encountered [or believe
they will encounter] doesn't turn that something into a categorical
imperative).
But this is more or less an aside: I two useful properties of
referencing: It is deterministic and it can be used for all kinds of
resources, not just memory. The first one is a conditio sine qua non
for the more complicated problems I have to deal with because of the
necessity to conform to 'some kind of protocol' wrt dealing with
'external entities' such as database servers. And the second makes my
(or anyone's) life much easier because there's generally no need to
worry about explicit resource management -- an object dies as soon as
it isn't used anymore and code tearing down whatever needs to be torn
down, insofar not already included in Perl, will run automatically
whenever this happens. A third one would be that it is possible to
have live Perl objects which are temporarily not reachable from
within the program, eg, send a pointer to some object through a kernel
IPC channel to another part of the program, for instance, some
top-level event loop, and ensure that it isn't deallocated by
increasing its reference count. This can also be very convenient.
Internally, they cause *huge* problems: a large number of bugs
in perl turn out to be caused by a refcount which got too high or too
low somewhere.
100% of all bugs in the perl implementation come from buggy code which
happens to be part of it. That's not exactly surprising ...