Dealing With Reference Cycles
There are a variety of ways of handling the problem of detecting and collecting reference cycles. One is that a system may explicitly forbid reference cycles. In some systems like filesystems this is a common solution. Another example is the Cocoa framework, which recommends avoiding reference cycles by using "strong" (counted) references for "parent-to-child" references, and "weak" (non-counted) references for "child-to-parent" references. Cycles are also sometimes ignored in systems with short lives and a small amount of cyclic garbage, particularly when the system was developed using a methodology of avoiding cyclic data structures wherever possible, typically at the expense of efficiency.
Another solution is to periodically use a tracing garbage collector to reclaim cycles. Since cycles typically constitute a relatively small amount of reclaimed space, the collection cycles can be spaced much farther apart than with an ordinary tracing garbage collector.
Bacon describes a cycle-collection algorithm for reference counting systems with some similarities to tracing systems, including the same theoretical time bounds, but that takes advantage of reference count information to run much more quickly and with less cache damage. It's based on the observation that an object cannot appear in a cycle until its reference count is decremented to a nonzero value. All objects which this occurs to are put on a roots list, and then periodically the program searches through the objects reachable from the roots for cycles. It knows it has found a cycle when decrementing all the reference counts on a cycle of references brings them all down to zero. An enhanced version of this algorithm by Paz et al. is able to run concurrently with other operations and improve its efficiency by using the update coalescing method of Levanoni and Petrank. See the paper for more.
Read more about this topic: Reference Counting
Famous quotes containing the words dealing with, dealing, reference and/or cycles:
“What we do in our dreams we also do when we are awake: we invent and make up the person we are dealing withand immediately forget that we have done it.”
—Friedrich Nietzsche (18441900)
“The wisest thing a parent can do is to let preschool children figure out themselves how to draw the human figure, or solve a whole range of problems, from overcoming Saturday-morning boredom to dealing with a neighborhood bully. But even while standing on the sidelines, parents can frequently offer support in helping children discover what they want to accomplish.”
—John F. Clabby (20th century)
“If Hitler invaded hell I would make at least a favourable reference to the devil in the House of Commons.”
—Winston Churchill (18741965)
“The stars which shone over Babylon and the stable in Bethlehem still shine as brightly over the Empire State Building and your front yard today. They perform their cycles with the same mathematical precision, and they will continue to affect each thing on earth, including man, as long as the earth exists.”
—Linda Goodman (b. 1929)